How can I get the position of current imag开发者_StackOverflow中文版e displaying in Gallery view while it is swiping?
So I don't think that is possible because of the way adapter views work. Basically most if not all calls to the adapter view's adapter have to be on the UI thread to work properly. And the animation is definitely on the UI thread. So since they both can't be happening at the same time on the same thread, you can't actually (accurately) read the position until the swiping animation is over.
If you ask the adapter getSelectedItemPosition() on any other thread it might give you the current position but might also be stale for some time since I am guessing the UI thread is going to update the value without checking for an exclusive lock.
We can get the position when we are swiping the image in gallery view,you overwrite Gallery View's setOnItemSelectedListener
.
We have two methods from that listener like
avatar_gallery.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent,
View view,
int position,
long id){
Log.v("Selected", ""+position);
}
@Override
public void onNothingSelected(AdapterView<?> parent){
}
}
精彩评论