Android Recycler View 的 notifyItemRemoved 动画被截断了。

3
我目前正在为Android 6编写的学校成绩管理器中工作,使用Java语言。我刚开始接触Android,所以并不是专家。
问题是: 如果我在RecycleView适配器上调用方法notifyItemRemoved(),并且最后一个CardView从左下角移动到右上角时,视图会被重新调整大小,动画也会被截断。
现在我不知道为什么这个视图会被重新调整大小,因为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>

我为RecycleView选择了GridLayoutManager作为LayoutManager。
subjectListView.setLayoutManager(new GridLayoutManager(ActivityContext, 2));

如何更新RecycleView:
SubjectAdapterObj.notifyItemRemoved(viewHolder.getAdapterPosition());

动画是默认的动画。
GridLayoutManager可能是问题吗?
视频示例:

Animation cut off


你正在使用的RecyclerView版本是什么? - Abbas
recycleview-v7-23.4.0 是你所指的吗? - Velrest
尝试重写RecyclerViewonMeasure方法并设置最大高度。 - Abbas
1
还要检查视图层次结构中是否有父级设置了height="wrap_content"。 - Abbas
@Abbas 如果我尝试覆盖RecyclerView,我总是会得到以下错误: android.view.InflateException:二进制XML文件行#65:二进制XML文件行#11:无法填充类。 - Velrest
这可能有多种原因,为RecyclerView添加更新后的xml和Java代码中的扩展RecyclerView - Abbas
1个回答

7

所以,我最终发现问题出在哪里。
实际上是由于NestedScrollView调整其子项的尺寸而导致的。
因此,您只需要简单地向NestedScrollView添加android:fillViewport="true"即可。

就是这样。我希望它能帮助一些人,虽然这不是一个非常困难的错误。我只是在错误的地方搜索了。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接