Scroll a ListView by pixels in Android

后端 未结 5 1421
隐瞒了意图╮
隐瞒了意图╮ 2021-02-06 08:50

I want to scroll the a ListView in Android by number of pixels. For example I want to scroll the list 10 pixels down (so that the first item on the list has its top

5条回答
  •  醉梦人生
    2021-02-06 09:40

    The supported way to scroll a ListView widget is:

    mListView.smoothScrollToPosition(position);

    http://developer.android.com/reference/android/widget/AbsListView.html#smoothScrollToPosition(int)

    However since you mentioned specifically that you would like to offset the view vertically, you must call:

    mListView.setSelectionFromTop(position, yOffset);

    http://developer.android.com/reference/android/widget/ListView.html#setSelectionFromTop(int,%20int)

    Note that you can also use smoothScrollByOffset(yOffset). However it is only supported on API >= 11

    http://developer.android.com/reference/android/widget/ListView.html#smoothScrollByOffset(int)

提交回复
热议问题