Answer the question
In order to leave comments, you need to log in
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:
<GridView
android:id="@+id/grid_view_test"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchMode="columnWidth" />
imageView = new ImageView(context);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setMaxHeight(200);
imageView.setAdjustViewBounds(true);
// Загрузка изображения и добавление в GridView
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question