view raw
yuku yuku - 10 months ago 42
Android Question

Scroll a ListView by pixels in Android

I want to scroll the a

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).

I thought the obviously visible
methods on ListView would do the job, but they don't, instead they scroll the whole list wrongly (In fact, the
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.

Sam Sam

The supported way to scroll a ListView widget is:


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

mListView.setSelectionFromTop(position, yOffset);,%20int)

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