Getting image position on GalleryView when scrolling?

How can I get the position of the current image displayed in the Gallery window while scrolling it?

+3
source share
2 answers

Therefore, I do not think that this is possible because of how adapter views work. Basically, most, if not all calls to the adapter, the adapter view must be in the user interface stream for the correct operation. And the animation is definitely in the user interface thread. Since both of them cannot occur simultaneously in the same thread, you cannot (accurately) read the position until the scroll animation ends.

If you ask the adapter getSelectedItemPosition () in any other thread, it may give you the current position, but it may also be deprecated for some time, since I assume that the UI thread will update the value without checking for an exclusive lock.

0
source

We can get a position, when we view the image in gallery mode, you are rewriting Gallery View setOnItemSelectedListener.

We have two methods from this listener, for example

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){
    }
}
0
source

Source: https://habr.com/ru/post/1782550/


All Articles