2

Hi I have a fragment with two RecyclerViews in it, one above the other.

The first is a list of items for the user to take an action on and the second is where the items will be populated once the action is taken. So when an item is removed from the top list it is added to the bottom list.

The issue I am having is when I remove an item from the top RecyclerView all the remaining items in the top RecyclerView move up to fill in the space left by the removed item, but this leaves a gap between the top and bottom RecyclerViews.

How can I move the bottom recyclerview up to fill in the gap created once an item is removed from the top RecyclerView

Here is my layout xml

<RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <android.support.v7.widget.RecyclerView
                android:layout_alignParentTop="true"
                android:id="@+id/pending_tasks"
                android:layout_marginTop="10dp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <android.support.v7.widget.RecyclerView
                android:layout_below="@id/pending_tasks"
                android:id="@+id/completed_tasks"
                android:layout_marginTop="10dp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

        </RelativeLayout>

I have tried calling invalidate() on the bottom RecyclerView but that has not worked. Any help would be appreciated, thanks!

Ameya Savale
  • 431
  • 1
  • 8
  • 21
  • Can you paste code of your adapters and what are you doing when an item is removed from the top recyclerview – Dibzmania Feb 12 '17 at 01:32

1 Answers1

1

It's impossible to update layout size once it's been displayed on the screen. If you modify the content of your RecyclerView you can't just simply refresh the layout to shrink it.

I would suggest using single RecyclerView and storing lower bound of the first list in some variable. Then simply update it accordingly to modifications in your first list.

Another solution which may help you: Change Relative layout width and height dynamically

Community
  • 1
  • 1