1

This is my XML code for RecyclerView item. The problem is, each item is shown in a whole page of app. please help me fixing this:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/rootlayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginLeft="8dp"
    android:background="@color/black"
    android:gravity="center">


  <com.makeramen.roundedimageview.RoundedImageView
    android:id="@+id/iv_wall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scaleType="centerCrop"
    app:riv_corner_radius="5dp" />

  <View
    android:id="@+id/view_wall"
    android:layout_width="160dp"
    android:layout_height="70dp"
    android:layout_alignParentBottom="true"
    android:background="@drawable/bg_gradient_black_round"
    android:gravity="center_vertical" />

Hanzala
  • 1,965
  • 1
  • 16
  • 43
Jack Smith
  • 21
  • 3

3 Answers3

2

you have set your item's width and height to match_parent which makes your item bigger than what you want. use smth like this:

      <RelativeLayout      xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/rootlayout"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_marginLeft="8dp"
android:background="@color/black"
android:gravity="center">


<com.makeramen.roundedimageview.RoundedImageView
    android:id="@+id/iv_wall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scaleType="centerCrop"
    app:riv_corner_radius="5dp" />

<View
    android:id="@+id/view_wall"
    android:layout_width="160dp"
    android:layout_height="70dp"
    android:layout_alignParentBottom="true"
    android:background="@drawable/bg_gradient_black_round"
    android:gravity="center_vertical" />
Matin Gdz
  • 217
  • 2
  • 13
2

set android:layout_height= "wrap_content" in your RelativeLayout

Hanzala
  • 1,965
  • 1
  • 16
  • 43
1

See what you are doing basically you are assigning layout_height = match_parent which means your every item will try to take full-screen space instead what you have to do is you can either fix the height of your item by giving static value like

android:layout_height="200dp"

another way is to let your view decide how much space it needs by using (recommended way)

android:layout_height="wrap_content"

Hope you understand the problem and get possible solutions.

Nouman Ch
  • 4,023
  • 4
  • 29
  • 42