3

I have updated support library to 23.2.1 and after that recyclerview items are appearing with big empty space. Though I am using recyclerview and it's parent view height as WRAP_CONTENT. My App fetches 10 items data at a time from the server and while scrolling to up it shows a progressbar at the bottom so at that time(while progressbar is showing) recyclerview items are showing with very large empty space.

enter image description here

Code for xml files for fragment and adapter repectively :

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

    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clipToPadding="false"
        android:paddingTop="?attr/actionBarSize"
        android:scrollbars="vertical"
        android:id="@+id/recycler_view"/>

    <include layout="@layout/date_picker_layout"
        android:id="@+id/date"
        android:layout_height="?attr/actionBarSize"
        android:layout_width="match_parent"/>

    <LinearLayout
        android:layout_width="@dimen/sort_view_width"
        android:layout_height="@dimen/sort_view_height"
        android:visibility="gone"
        android:id="@+id/sort_layout"
        android:background="@drawable/date_picker_selector"
        android:baselineAligned="false"
        android:weightSum="2"
        android:orientation="horizontal"
        android:divider="@drawable/vertical_divider"
        android:layout_gravity="center"
        android:gravity="center"
        android:showDividers="middle"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_marginRight="@dimen/margin_large"
        android:layout_marginBottom="@dimen/margin_large">

        <ImageView
            android:layout_width="0dp"
            android:layout_height="@dimen/button_size"
            android:layout_weight="1"
            android:padding="@dimen/margin_xxsmall"
            android:id="@+id/low_to_high"
            android:src="@drawable/ic_sort_down"/>

        <ImageView
            android:layout_width="0dp"
            android:layout_height="@dimen/button_size"
            android:layout_weight="1"
            android:padding="@dimen/margin_xxsmall"
            android:id="@+id/high_to_low"
            android:src="@drawable/ic_sort_up"/>

    </LinearLayout>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:drawableBottom="@drawable/three_dot"
        android:visibility="gone"
        android:textSize="@dimen/textsize_medium"
        android:text="@string/coming_soon"
        android:id="@+id/no_items"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" />
</RelativeLayout>

adapter.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:wheel="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/itemview">

    <ImageView
        android:id="@+id/image"
        android:layout_height="@dimen/list_image_height"
        android:layout_width="match_parent"
        android:scaleType="centerCrop"
        android:adjustViewBounds="true"/>

    <com.example.views.CircularProgressWheel
        android:layout_width="@dimen/progressbar_width"
        android:layout_height="@dimen/progressbar_height"
        android:id="@+id/progress_bar"
        android:visibility="gone"
        wheel:matProg_barColor="@color/primary"
        wheel:matProg_progressIndeterminate="true"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/gradient"
        android:layout_alignBottom="@id/image"
        android:id="@+id/relativeLayout2">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/name"
            android:id="@+id/title"
            android:textColor="@color/white"
            android:textSize="@dimen/textsize_medium"
            android:layout_toLeftOf="@+id/price"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_marginLeft="@dimen/margin_xsmall"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/margin_xsmall"
            android:text="@string/location"
            android:id="@+id/location"
            android:textColor="@color/white"
            android:textSize="@dimen/textsize_medium"
            android:layout_below="@+id/title"
            android:layout_toLeftOf="@+id/price"
            android:layout_alignLeft="@+id/title"
            android:layout_alignStart="@+id/title" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/price"
            android:layout_marginRight="@dimen/margin_xsmall"
            android:id="@+id/price_actual"
            android:textColor="@color/white"
            android:textSize="@dimen/textsize_medium"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/price"
            android:id="@+id/price"
            android:textColor="@color/white"
            android:textSize="@dimen/textsize_medium"
            android:layout_below="@+id/title"
            android:layout_alignRight="@+id/price_actual"
            android:layout_alignEnd="@+id/price_actual" />

    </RelativeLayout>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="@dimen/margin_xxsmall"
        android:textSize="@dimen/textsize_medium"
        android:background="@drawable/cancel_button_selector"
        android:visibility="gone"
        android:textColor="@color/white"
        android:text="@string/sold_out"
        android:id="@+id/sold_out"
        android:layout_marginRight="@dimen/margin_xsmall"
        android:layout_above="@+id/relativeLayout2"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

</RelativeLayout>
Krishna Meena
  • 5,693
  • 5
  • 32
  • 44

1 Answers1

8

Make sure your recycler view height is set to wrap_content. 23.2 introduced wrap content functionality for RecylerView and you should have the height as wrap_content if you want your RecyclerView work as it was working before.

Quote from Android Developers Blog

Due to this change, make sure to double check the layout parameters of your item views: previously ignored layout parameters (such as MATCH_PARENT in the scroll direction) will now be fully respected.

arsent
  • 6,975
  • 3
  • 32
  • 31
  • getting the same behaviour either I set it to match_parent or wrap_content – Krishna Meena Mar 17 '16 at 19:06
  • Can you please post some code ? Your adapter item xml and recyclerview xml would be ideal. – arsent Mar 17 '16 at 19:22
  • I have posted the code for both layouts – Krishna Meena Mar 18 '16 at 05:57
  • 1
    Not sure if you already solved this or not. I'm using support library version 23.4.0 and followed the suggestions above, but still facing the same problem as yours. Using wrap_content for item views, will display the items properly, but after you scroll it, there will be large gap between item. In my case i tried to set the RecylerView(not the item view) back to match_parent. To put it, in my case: - RecyclerView is match_parent - Item view is wrap_content May be it will work to in your case. – Reza May 12 '16 at 05:04
  • 2
    My progressbar's layout width was MATCH_PARENT that's why is was appearing on the full screen, after setting it to WRAP_CONTENT my problem is solved. – Krishna Meena Jun 05 '16 at 19:32
  • 2
    in my case, the xml linked to my Adapter class on method onCreateViewHolder had a RelativeLayout with android:layout_heigh="match_parent", I changed it to "wrap_content" andit worked fine! – Thiago Pereira Jun 09 '16 at 21:09