在Android的像素滚动一个ListView [英] Scroll a ListView by pixels in Android
问题描述
我想通过像素数来滚动一个的ListView
Android中。例如,我想滚动列表10象素(让名单上的第一个项目有它的前10像素行隐藏)。
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 10 pixel rows hidden).
我以为明显可见 scrollBy
或 scrollTo
上的ListView方法将做的工作,但他们不,相反,他们滚动整个列表错误(其实, getScrollY
总是返回零,即使我已滚动使用我的手指列表。)
I thought the obviously visible scrollBy
or scrollTo
methods on ListView would do the job, but they don't, instead they scroll the whole list wrongly (In fact, the getScrollY
always return zero even though I have scrolled the list using my finger.)
我在做什么是我捕捉轨迹球的事件,我想根据轨迹球的动作顺利滚动列表视图。
What I'm doing is I'm capturing Trackball events and I want to scroll the listview smoothly according to the motion of the trackball.
推荐答案
要滚动 ListView控件支持的方式
widget是:
The supported way to scroll a ListView
widget is:
mListView.smoothScrollToPosition(位置);
<一个href=\"http://developer.android.com/reference/android/widget/AbsListView.html#smoothScrollToPosition(int)\">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(位置,yOffset);
<一个href=\"http://developer.android.com/reference/android/widget/ListView.html#setSelectionFromTop(int,%20int)\">http://developer.android.com/reference/android/widget/ListView.html#setSelectionFromTop(int,%20int)
请注意,您还可以使用 smoothScrollByOffset(yOffset)
。然而,它仅支持API> = 11
Note that you can also use smoothScrollByOffset(yOffset)
. However it is only supported on API >= 11
<一个href=\"http://developer.android.com/reference/android/widget/ListView.html#smoothScrollByOffset(int)\">http://developer.android.com/reference/android/widget/ListView.html#smoothScrollByOffset(int)
这篇关于在Android的像素滚动一个ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!