开发者

Get the position of an element in Android's List View

my friend and i develop a Android programm.

Now we 开发者_如何学运维got to the question if it's possible to get the actual position of an ListElement.

Example: You drag the list up and down, and now you want to konw which element is on the center of the screen?

can anyone help us?


you can use the ListView functions

getFirstVisiblePosition() 

and

getLastVisiblePosition()

so you can calculate whats element on the center of the screen.


There's a function AbsListView#pointToPosition which will return the position in the adapter for the child view at the specified point. You can probably call that with half the height and width of the ListView to get the position for the center item. There is also AdapterView which is one of the parents of ListView that has some functions for returning item positions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜