0

I have this RecyclerView

 <android.support.v7.widget.RecyclerView
    android:id="@+id/rcView"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

if I changes height from match_parent to wrap_content it won't display images but otherwise does, what's wrong with it.

MainActivity layout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<android.support.v7.widget.RecyclerView
    android:id="@+id/rcView"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

Recylerview Item Layout

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
    android:id="@+id/imageView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

Prashant Abdare
  • 2,175
  • 14
  • 24

1 Answers1

1

Finally found the solution it is AdjustViewBounds property for ImageView. After setting it to true now I can adjust the height and width the recycler_view_item the way I want.

Here is revised code for recycler_view_item.

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<ImageView
    android:adjustViewBounds="true"
    android:layout_margin="1dp"
    android:id="@+id/imageView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" /> </RelativeLayout>

this link was also helpful.

Prashant Abdare
  • 2,175
  • 14
  • 24