B
B
bizir2016-02-02 19:21:38
Android
bizir, 2016-02-02 19:21:38

How to tiling images?

Good evening. I need to make a gallery with images of different sizes of this kind, MniSNHEHJRE.jpg3eH0mH8kqx0.jpghow can this be implemented?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
aol-nnov, 2016-02-02
@aol-nnov

well, how-how ... somehow so !

O
Oleg Gamega, 2016-02-02
@gadfi

recyclerview to help you

I
itdroid, 2016-02-03
@itdroid

Hello, such markup can be done using RecyclerView + GridLayoutManager.
For the GridLayoutManager, set a custom GridLayoutManager.SpanSizeLookup and determine how many cells the item will occupy in it. For example, like this:

RecyclerView recyclerView = (RecyclerView) findViewById(android.R.id.recycler);
//грид в 3 колонки
GridLayoutManager gridLayoutManager= new GridLayoutManager(context, 3); 
gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
    @Override
    public int getSpanSize(int position) {
        return position == 0 ? 3 : 1;
    }
});
recyclerView.setLayoutManager(gridLayoutManager);

Now the first picture will occupy all 3 columns, and all subsequent ones one at a time.
We figured out the width of the pictures, it remains to deal with the height.
For example, you can do this: so that the height is considered dynamically and depends on the width of the image, let's say height = (width * 3)/4. This can be done by deriving from ImageView and overriding the onMeasure method .
Since the GridLayoutManager will be responsible for the width of the image, and the height will be dynamically calculated, as a result we will get something similar to the second screenshot.
By writing more complex logic in getSpanSize, you can get the markup as in the first screenshot.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question