twister_void
twister_void

Reputation: 1389

Displaying Multiple Image of different size in recycler view

I have a typical recycler adapter set up. Some of the items in the adapter have images, sometimes just one image, maximum 12. I want to display images, like the one below, depending on the number of images in each item: Real Image Sample sizes Currently, I used different layout files to show a different set of images. But the problem is images are of varied sizes and I have defined set for 4 images only I am using GLIDE Library to display images.

Code for if images are 4, They will resize to bigger image size

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="3"
    android:minHeight="@dimen/dp_200"
    android:orientation="horizontal">

    <ImageView
        android:id="@+id/image4"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:adjustViewBounds="true"
        android:contentDescription="@string/content_desc"
        android:scaleType="fitXY" />

    <ImageView
        android:id="@+id/image5"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:adjustViewBounds="true"
        android:contentDescription="@string/content_desc"
        android:scaleType="fitXY" />

    <ImageView
        android:id="@+id/image6"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:adjustViewBounds="true"
        android:contentDescription="@string/content_desc"
        android:scaleType="fitXY" />

</LinearLayout>

I am looking for any libraries available which should work with Target API 29. The previous solution is not working with newer Target API.

Upvotes: 2

Views: 1616

Answers (2)

C&#244;ng Hải
C&#244;ng Hải

Reputation: 5241

I think you can use flexboxlayoutmanager, you can check you sample here

Upvotes: 2

Rohit Sharma
Rohit Sharma

Reputation: 1414

Use a horizontal Recycler View inside vertical Recycler View.By this width of your images will also vary accordingly.

Upvotes: 0

Related Questions