A
A
afna2016-05-19 16:52:09
Java
afna, 2016-05-19 16:52:09

How to create an image gallery with slide?

Good day to all!
Faced here with such task. Make an image gallery with slide.
d648437c9d7240cbafd2ffe6f793f078.png
I think like this:
1. Lay out an ImageView grid type screen in a RelativeLayout, for example.
2. Count the number of pictures, divide by the number that fit on one screen. This will be the number of fragments that we will add to the ViewPager.
When you click on the picture, you need to show the photo in full screen. those. you need to somehow refer to this photo
. But with such a scheme, I don’t know how to refer to a specific photo on a specific fragment.
Another option is to make the RecycleView horizontal

mRecyclerView.setLayoutManager(new GridLayoutManager(mActivity, 3));

But how to make it swipe like a ViewPager. As I understand it, you need to override the scrolling methods, but I feel that I'm getting bogged down.
Maybe there is a ready-made solution or someone will tell you how to do this correctly?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
itdroid, 2016-05-19
@itdroid

As for me, the first option is OK. The only thing I would replace the ImageView + RelativeLayout bundle with is a self-written ViewGroup component that takes the number of columns and columns in the grid and places the child views in the right places.
The problem with understanding which ImageView was clicked on is solved simply: when you add an ImageView to the container, save the uri to the image as a tag, and when this ImageView arrives onClickListener , you will get the uri using the view.getTag() method.
While writing, I thought about a possible problem: since the ViewPager keeps 3+ pages with pictures in memory, there may be problems due to OutOfMemory, so you need to properly resize the preview of the pictures.
From my point of view, this is the easiest option (of course, if there is no ready-made solution :).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question