Maalur Maalur - 2 months ago 33
Java Question

Android Recycler View notifyItemRemoved animation cut off

I'm currently working on a Grade Manager for school written in Java for Android 6. I just started with Android so I'm no expert.

The Problem:

If I call the method

notifyItemRemoved()
on my RecycleView Adapter and the last CardView moves from the left bottom place to the upper right place, the View is resized and the animation is cut of.

Now I don't know why that view is resized because RecycleView's
layout_height
attribute is
match_parent
.

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".SemesterActivity"
tools:showIn="@layout/activity_semester">

<android.support.v7.widget.RecyclerView
android:id="@+id/subject_list_view"
android:padding="20dp"
android:layout_below="@+id/title"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"/>

</android.support.v4.widget.NestedScrollView>


I took a
GridLayoutManager
as LayoutManager for the RecycleView.

subjectListView.setLayoutManager(new GridLayoutManager(ActivityContext, 2));


How i update the RecycleView:

SubjectAdapterObj.notifyItemRemoved(viewHolder.getAdapterPosition());


The animation is the default animation.

Could the
GridLayoutManager
be the problem?

Video Example:

Animation cut off

Sorry. English is not my native language.

Answer

So I finally found out what the Problem was.
It actually was the NestedScrollView which resizes it's children.
So what you need to do is simply add android:fillViewport="true" to your NestedScrollView.

Thats it. I hope it helps someone although it's not a really difficult bug. I just searched at the wrong places.