【问题标题】:Animation is not working in RecyclerView in NestedScrollView in Android?动画在 Android 的 NestedScrollView 中的 RecyclerView 中不起作用?
【发布时间】:2020-07-22 13:04:44
【问题描述】:

我在NestedScrollView的LinearLayout中使用了两个RecyclerView,见xml文件。

    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/rvData1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/rvData2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
        </LinearLayout>
    </androidx.core.widget.NestedScrollView>

我在onBindViewHolder Adapter 类中编写了代码动画

            holder.parentView.setAnimation(AnimationUtils.loadAnimation(getApplicationContext(), R.anim.right_to_left));

当我删除代码 NestedScrollView 时,我的所有代码都很完美,然后动画完美运行,并且 NestedScrollView 可见,然后它不像简单地显示适配器行中的所有项目那样运行动画。

Android 人员分享您所做的最佳体验。 谢谢!

【问题讨论】:

  • 您是否在设置动画之前尝试禁用嵌套滚动?那是您当前和最终的 XML 吗?为什么要使用 LinearLayout 作为 RV 的父级?
  • 我在线性布局中使用 3 rv,而父嵌套滚动就是这样。动画在nestedscoll 中不起作用。如果您知道如何解决它?
  • NestedScrollView 支持多个子视图,因此您可以将 3 个 RV 直接放在 NestedScrollView 中,无需使用 LinearLayout。当您使用仅支持一个孩子的 ScrollView 时使用该策略。更改它,因为这可能会导致您的动画出现问题
  • @AgustinMagne 关于 NestedScrollView 的问题不是线性布局,并且动画在 nestedsv 内不起作用,如果我禁用了 nestedsv,它就会起作用。感谢支持,请尝试其他人。
  • 这只是一个建议,因为动画可能很棘手,而且糟糕的布局层次结构会搞砸事情,这对我来说确实有好几次。祝你的问题伙伴好运。

标签: android animation android-recyclerview android-nestedscrollview


【解决方案1】:

改变你的编码风格,你能做嵌套的recyclerview吗,我的意思是,在 一个recyclerview 把recyclerview 的其余部分。你可以创建这种 使用 VIEW_TYPE 进行回收查看

【讨论】:

  • 好的。你能给我举个例子,这正是你所说的代码吗?
  • 您可以使用MergeAdapter 轻松实现此效果,而无需重写您的适配器。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-02-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-04
相关资源
最近更新 更多