smoothScrollToPositionFromTop (int position, int offset) > 안드로이드 플랫폼 지식 공유

본문 바로가기

사이트 내 전체검색


안드로이드 플랫폼 지식 공유

smoothScrollToPositionFromTop (int position, int offset)

페이지 정보

작성자 LUG 작성일14-12-05 15:57 조회16,283회 댓글0건

본문

public void smoothScrollToPositionFromTop (int position, int offset)

Added in API level 11 

 

Smoothly scroll to the specified adapter position. The view will scroll such that the indicated position is displayed offset pixels below the top edge of the view. If this is impossible, (e.g. the offset would scroll the first or last item beyond the boundaries of the list) it will get as close as possible.

 

Parameters

position Position to scroll to

offset Desired distance in pixels of position from the top of the view when scrolling is finished 

 

public void smoothScrollToPosition (int position)

Added in API level 8

 

Smoothly scroll to the specified adapter position. The view will scroll such that the indicated position is displayed.

 

Parameters

position Scroll to this adapter position. 

 

public void setSelectionFromTop (int position, int y)

Added in API level 1

 

Sets the selected item and positions the selection y pixels from the top edge of the ListView. (If in touch mode, the item will not be selected but it will still be positioned appropriately.)

 

Parameters

position Index (starting at 0) of the data item to be selected.

y The distance from the top edge of the ListView (plus padding) that the item will be positioned. 

 

===

 

try {

if (Build.VERSION.SDK_INT >= 11) {

main_lv_filelist.smoothScrollToPositionFromTop(pos, 0);

} else if (Build.VERSION.SDK_INT >= 8) {

int firstVisible = main_lv_filelist.getFirstVisiblePosition();

   int lastVisible = main_lv_filelist.getLastVisiblePosition();

   if (pos < firstVisible) {

main_lv_filelist.smoothScrollToPosition(pos);

   } else {

main_lv_filelist.smoothScrollToPosition(pos + lastVisible - firstVisible - 2);

   }

} else {

main_lv_filelist.setSelectionFromTop(pos, 0);

}

} catch (Exception e) {} 

댓글목록

등록된 댓글이 없습니다.



Copyright © www.lug.or.kr. All rights reserved.
상단으로
PC 버전으로 보기