0

I'm using recycler view to display item, my item is include image and text. And im using StaggeredGridLayoutManager to display this.

a part of my layout:

 <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
            <android.support.v7.widget.CardView
                android:id="@+id/cvExhibit"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                xmlns:cardview="http://schemas.android.com/apk/res-auto"
                cardview:cardCornerRadius="@dimen/cardview_corner_radius"
                cardview:cardUseCompatPadding="true"
                >
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">
                    <ImageView
                        android:id="@+id/imgExhibit"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:scaleType="fitXY"

                        />
                </LinearLayout>

            </android.support.v7.widget.CardView>

            <ProgressBar
                android:id="@+id/pbItemMainScreen"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:elevation="2dp"
                android:visibility="visible"
                android:indeterminateTint="@color/colorBlueLight"
                android:indeterminateTintMode="src_in"
                />

        </RelativeLayout>

And result: result1

I wan't to fit image full larger both width and height, but the result like this: result2

and here a code for result2:

<RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <android.support.v7.widget.CardView
                android:id="@+id/cvExhibit"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                xmlns:cardview="http://schemas.android.com/apk/res-auto"
                cardview:cardCornerRadius="@dimen/cardview_corner_radius"
                >
                <ImageView
                    android:id="@+id/imgExhibit"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:scaleType="fitXY"

                    />
            </android.support.v7.widget.CardView>

            <ProgressBar
                android:id="@+id/pbItemMainScreen"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:elevation="2dp"
                android:visibility="visible"
                android:indeterminateTint="@color/colorBlueLight"
                android:indeterminateTintMode="src_in"
                />

        </RelativeLayout>

How can I do the image fit by width, and then it height auto fit by image size? like this:

My dream result

Phuc sino
  • 29
  • 7

1 Answers1

0

Please try this

<ImageView
    android:id="@id/imgExhibit"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true"
    android:scaleType="fitCenter" />
Dharmesh G
  • 67
  • 1
  • 5
Shravan Jain
  • 720
  • 1
  • 11
  • 32