开发者

How to change ScrollView's position after touch?

I'm trying to make a ScrollView with a list of numbers in it that the user can select from. After the user touches and scrolls, after the finger is lifted I want the scroll to "snap" to the item in the middle of the ScrollView and give me the output. My ScrollView contains a vertical linear layout with TextView objects in it. The ScrollView's vertical size is about 60sp.

I thin开发者_Go百科k this would involve the ScrollView.onTouch with a ACTION_UP, but I don't know how to use it. Also, is there a way to get an item's index or value based on a position in the list?

Thanks!


Are you using ListView? See Hello ListView to get started with one. I'm not sure what exactly you mean by snapping to the item in the middle, but when scrolling a ListView I believe you will always end up with the top of the listView aligned with the top of an item.

As to the item's index or position, a ListView item has two concepts. The position is the location of the item in the whole list (typically the ArrayAdapter that was used to fill the ListView). The id is the visible position on the screen. Thus, if top item of the screen would have id 0, but may have postion 20. See Javadocs

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜