A
A
Andrey Myvrenik2016-02-10 13:03:13
Android
Andrey Myvrenik, 2016-02-10 13:03:13

How to dynamically display multiple ImageViews in a grid layout using available space efficiently?

Many applications implement similar display of images. When there is 1 image in a post, it uses all the space available for it. If there are more images, they share the space among themselves in this form, as seen in the screenshot. If an image does not fit within the free space allocated to it, it is cropped:
android:scaleType="centerCrop"
How can this effect be achieved? ImageView are added in code. I've tried using the GridView as it is, but I haven't been able to get even one image to use all of its available space. Layout:
s_1455095797_5315072_6474f671e9.jpg
h_1455098125_1500586_067786e873.png

<GridView
    android:id="@+id/grid_view_test"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:stretchMode="columnWidth" />

Added ImageView:
imageView = new ImageView(context);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setMaxHeight(200);
imageView.setAdjustViewBounds(true);
// Загрузка изображения и добавление в GridView

What types to use for this? Are there standard methods? Are third party libraries available for this? Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lomikman, 2016-02-10
@lomikman

Try StaggeredGridLayoutManager
inducesmile.com/android/android-staggeredgridlayyou...
https://dzone.com/articles/be-lazy-productive-android-1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question