How to scroll gridview to position?

后端 未结 3 2028
挽巷
挽巷 2020-12-06 07:35

I have 30 images on grid view (3 images per row). If user select 20th image and go to next screen and come back then I want to focus to that position. I used following line

3条回答
  •  旧时难觅i
    2020-12-06 07:59

    solution that worked for me was combine code from Monali and Sreedev (thank you Monali and Sreedev):

    private int gridviewVerticalPositionWhenThumbnailTapped;
    

    ...

    // save vertical position of gridview screen, will use to re-find this location if user follows a usre and gridview gets redrawn
    gridviewVerticalPositionWhenThumbnailTapped = gridview.getFirstVisiblePosition();
    

    later in app...

    // scroll gridview to vertical position pre user tap follow                
    gridview.setSelection(gridviewVerticalPositionWhenThumbnailTapped);
    

提交回复
热议问题