How to create a gallery of images from sliding?

Good day Everyone!
Faced with this task. To make a picture gallery with sliding.
d648437c9d7240cbafd2ffe6f793f078.png

I think so:
1. To make a screen mesh type ImageView in a RelativeLayout, for example.
2. Count the number of images divided by the number that fit on one screen. This will be the number of fragments that we will add in the ViewPager.

When you click on the picture you want to show photos in full screen. ie you need to refer to this photo
But in this scheme I don't know how to refer to a specific photo on a specific fragment.

Another option is to make horizontal RecycleView
mRecyclerView.setLayoutManager(new GridLayoutManager(mActivity, 3));


But how to make it swipesy as ViewPager. I understand I need to override the methods of scrolling, but I feel that objasnu.

Maybe there is a ready solution or someone tell me how to do it?
July 9th 19 at 12:56
1 answer
July 9th 19 at 12:58
As for me, the first option is OK. The only thing I would replace a bunch of ImageView + RelativeLayout in ViewGroup in-house component, which takes the number of columns and columns in the grid and sets the child view function in the right places.
The problem with understanding what the ImageView is clicked is simple: when I add ImageView in a container, save the uri to the image as tag and OnClickListener will arrive when this ImageView, you will get the uri of the view method.getTag().
While writing, thought of a possible problem: since the ViewPager holds in memory a 3+ old women with pictures, can be a problem due to OutOfMemory, so you need to properly resize the preview images.
From my point of view this is the easiest option (of course, if there is no ready-made solutions).
Thanks for the reply.
Implemented using a GridView. It binds to the adapter, which is still possible to catch clicking on a particular item. - Frederick commented on July 9th 19 at 13:01

Find more questions by tags AndroidJavaMobile development