1

Each item should cover 70% of the screen width. Though 70% of the screen is filled, I am getting 30% of blank space and next item is starting after it. Here is the layout -

<?xml version="1.0" encoding="utf-8"?>
<android.support.percent.PercentRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_weight="4"
        app:cardCornerRadius="2dp"
        app:cardElevation="2dp"
        app:cardPreventCornerOverlap="false"
        app:cardUseCompatPadding="true"
        app:contentPadding="2dp"
        app:layout_widthPercent="70%">

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:orientation="vertical">

            <ImageView
                android:id="@+id/image_test"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="centerCrop"/>

        </FrameLayout>
    </android.support.v7.widget.CardView>
</android.support.percent.PercentRelativeLayout>
mihirjoshi
  • 12,161
  • 7
  • 47
  • 78
  • Try to set `app:layout_widthPercent="70%"` to your `PercentRelativeLayout` and set `CardView` to `match_parent` – Ivan Ivanov Mar 29 '16 at 08:42
  • The problem is not with this layout, it's with the layout which holds the recyvlerview. If you have added layout_margintop anywhere in there anything similar to that please remove it – Sumanth Jois Mar 29 '16 at 08:43
  • @IvanIvanov How can you provide percentage width to the PercentRelativeLayout itself. Last time I check percentage is relative. – mihirjoshi Mar 29 '16 at 09:08

1 Answers1

0

Before Android Support Library, revision 23.2.1 recyclerView did not considered the height(vertical) or width(Horizontal) of his itemView. It always wraps it up.

But Now it considers the height or width. In your case it's width.

So, make your layout_width , match_parent to wrap_content

Sayem
  • 4,891
  • 3
  • 28
  • 43
  • layout_width of recyclerview ? – mihirjoshi Mar 29 '16 at 09:08
  • child item is a `PercentRelativeLayout`, making it wrap wont make layout 70% of its parent. Its `match_parent ` for a reason, so that child items can take 70% of the screen. – mihirjoshi Mar 29 '16 at 09:32
  • in that case you need to make a work around because what will the size of match_parent it does not know. may be takes a default max width when you set it match_parent. you can calculate the parcent manually and set it to you cardView in onCreateVeiwHolder. – Sayem Mar 29 '16 at 09:46