简体   繁体   English

Android Recycler View notifyItemRemoved动画已切断

[英]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. 我目前正在使用Java for Android 6编写学校的成绩管理器。我刚开始使用Android,所以我不是专家。

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. 如果我在RecycleView Adapter上调用方法notifyItemRemoved() ,并且最后一个CardView从左下方移动到右上方,则将调整View的大小并剪切动画。

Now I don't know why that view is resized because RecycleView's layout_height attribute is match_parent . 现在我不知道为什么要调整视图的大小,因为RecycleView的layout_height属性是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. 我将GridLayoutManager用作RecycleView的LayoutManager。

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

How i update the RecycleView: 我如何更新RecycleView:

SubjectAdapterObj.notifyItemRemoved(viewHolder.getAdapterPosition());

The animation is the default animation. 动画是默认动画。

Could the GridLayoutManager be the problem? GridLayoutManager可能是问题吗?

Video Example: 视频示例:

动画切断

Sorry. 抱歉。 English is not my native language. 英语不是我的母语。

So I finally found out what the problem was. 所以我终于发现了问题所在。
It actually was the NestedScrollView which resizes it's children. 实际上是NestedScrollView调整了其子级的大小。
So what you need to do is to simply add android:fillViewport="true" to your NestedScrollView . 因此,您需要做的只是将android:fillViewport="true"NestedScrollView

Thats it. 而已。 I hope it helps someone although it's not a really difficult bug. 我希望它对某人有帮助,尽管这并不是一个真正困难的错误。 I just searched at the wrong places. 我只是在错误的地方搜索。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM