我有下一个结构:
活动1:
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/FAB_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</android.support.design.widget.CoordinatorLayout>
活动2:
Form to add new item to the recycler View.
RecyclerView的XML:
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"/>
我在第二个Activity中创建了该项,并使用startActivityForResult在activity one中添加该项,然后调用adapter.notifyItemInserted(0)。
问题是当添加项目时,插入动画无法正常工作,但如果我不使用第二个活动并在第一个活动中创建项目并添加到适配器,它可以正常工作。
¿我该如何解决这个问题?
答案 0 :(得分:1)
您的xml结构可能存在问题,请检查layout_behavior
并使用CoordinatorLayout
Android CoordinatorLayout
有关如何使用CoordinatorLayout
和layout_behavior
检查this blog
我还发现android:animateLayoutChanges="true"
在可滚动的RecyclerView
中使用非常小故障/错误,我建议不要使用它。对于不可滚动的RecyclerView
,它可以正常工作。