0

I have an issue where i would like to fill the expanded space with a custom color or gradient in that matter. However RecyclerView works in a way that it expands the rows by leaving an empty space between items which results in seeing a white background (screenshot) or whatever is the background color. The empty space gets filled after the expansion animation, where onBindViewHolder gets called.

Could this be solved somehow, where I could fill this empty space with a custom view, so it gets epxanded nicely without color flickering?

Is there a way I could attach a listener to the animation and overlay it with a virtual view for that time?

Right before the child views are shown:

Right before the child views are shown

After the child views are shown (group is expanded)

After the child views are shown (group is expanded)

EDIT: added RecyclerView's xml as requested

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
    android:id="@+id/recycler_view"
    style="@style/myRecyclerViewStyle"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>
</FrameLayout>

group_item.xml

<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="@dimen/list_group_item_height"
android:background="@android:color/holo_green_light"
android:clickable="true"
android:foreground="?attr/selectableItemBackground">

<TextView
    android:id="@android:id/text1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"/>

</FrameLayout>

child_item.xml

<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="@dimen/list_item_height"
android:background="@android:color/holo_green_light"
android:clickable="true">

<TextView
    android:id="@android:id/text1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"/>

</FrameLayout>

Even if i change all the heights to wrap_content its still the same, the animation just epxands the views and leaves an empty space (recyclerView's background), which i would like to fill somehow.

This is taken from this library: https://github.com/h6ah4i/android-advancedrecyclerview

box
  • 4,450
  • 2
  • 38
  • 38
  • post your xml file – Pratik Popat Feb 16 '17 at 09:13
  • @PratikPopat Added the xml of the RecyclerView. – box Feb 16 '17 at 09:21
  • Change height of your custom row layout from `match_parent` to `wrap_content`. – Piyush Feb 16 '17 at 09:23
  • I changed it, it doesn't affect it...My question isn't related to layout height issues, but fundamental recylerView animation handling. Can i listen to those changes perhaps? – box Feb 16 '17 at 09:29
  • hey, were you able to fix it ? I am having the same problem, I am adding an item to ArrayList and calling `Adapter.notifyItemInserted(mData.size()-1)` it leaves a big gap between items. – amira Dec 13 '18 at 14:08

1 Answers1

0

This should be because you might have given match_parent in your adapter classes. Hope this is helpful :)

Jeevanandhan
  • 1,073
  • 10
  • 18
  • No, this doesn't affect the notifiItemInserted...it just wraps the RecyclerView...I added wrap_content but no changes – box Feb 16 '17 at 09:24