在网上看到很多人想得到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,打印停止位置