Skip to content

Android:ListView

ListView 현재 위치 기억 및 Scroll 이동

ListView의 현재위치를 INDEX로 획득하는 방법과, 해당 INDEX를 사용하여 이동하는 방법은 아래와 같다.

// 현재 위치(INDEX) 획득.
int position = listView.getFirstVisiblePosition();
// 해당 INDEX 이동.
ListView.setSelection(position);

Height of ListView

아래의 함수를 종합적으로 사용하여 리스트뷰의 높이를 구할 수 있다.

  • ListView.getChildCount(): 리스트뷰상 현재 화면에 보여지는 자식뷰의 수.
  • ListView.getChildAt(index): 리스뷰상 현재 화면에 보여지는 자식뷰들만 인덱스로 제어 가능.
  • ListView.getChildAt(index).getHeight(): 자식뷰의 높이.

ListView 강제 스크롤

아래와 같이 smoothScrollBy함수를 사용하면 된다.

ListView listView;
// ...
/** <code>y</code>만큼 스크롤한다. */
public void scrollCattingListBy(int y) {
    Assert.assertNotNull(listView);
    final int SCROLL_DURATION = 200;
    listView.smoothScrollBy(y, SCROLL_DURATION);
}

Favorite site