您的位置:首页 > 移动开发 > Android开发

Android Gallery获取滑动停止的位置

2012-06-22 10:51 399 查看
在网上看到很多人想得到Gallery滑动停止的位置,大部分是通过起线程的方式来获取,嘿嘿,看了一下源码查了API,

发现一个方法:

public void setCallbackDuringFling (boolean shouldCallback)

Since: API Level 1

Whether or not to callback on any
getOnItemSelectedListener()
while the items are being flinged. If false, only the final selected item will cause the callback. If true, all items between the first and the final will cause callbacks.

大概意思是,设为false,
getOnItemSelectedListener()中才返回gallery的停止位置position,滑动过程中不触发getOnItemSelectedListener()事件。


在getOnItemSelectedListener() 中
public void onItemSelected(final AdapterView<?> parent, final View view,
final int position, long id)
{
System.out.println("itme = " + id);
}


当滑动停止后才返回Item,打印停止位置
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: