【问题标题】:Android Studio Recyclerview (horizontal) - remove animation when leaving viewAndroid Studio Recyclerview (horizo​​ntal) - 离开视图时移除动画
【发布时间】:2020-04-14 11:52:18
【问题描述】:

我在线性布局中创建了一个简单的回收器视图。当我向右滚动时,我想要这些项目 消失在我的 frameLayout 后面。 (看起来您再也看不到这些项目了,因为它们位于 frameLayout 后面)。

不幸的是,这些项目确实会移动到看不见的墙(回收站视图的左边框)后面,而不是在我的 frameLayout 后面。有没有办法删除离开recyclerview的项目的动画?

感谢您的帮助!

代码:

  <androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="300dp"
    android:layout_marginTop="10dp"
    android:orientation="horizontal">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/rv_exerciseCards"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:animateLayoutChanges="false"
        android:paddingLeft="40dp"

        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>

    <FrameLayout
        android:id="@+id/frameLayout"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <ImageView
            android:layout_width="50dp"
            android:layout_height="300dp"
            android:layout_marginLeft="-10dp"
            android:background="@drawable/view_newexercise_deck"
            android:elevation="4dp" />

        <com.example.projecttraining0.VerticalTextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginLeft="-5dp"
            android:elevation="4dp"
            android:rotation="180"

            android:text="My Exercises"
            android:textAlignment="center"
            android:textColor="@color/colorPrimaryDark"
            android:textSize="18sp" />
    </FrameLayout>

screenshot

【问题讨论】:

  • 你能提供截图吗?
  • 感谢您的回答,我已经添加了截图。我的问题是卡消失的那条线。我想你可以在底部的蓝色部分看到最​​好的。

标签: android android-recyclerview android-animation


【解决方案1】:

通过使用 LinearLayout,您的 FrameLayout 和 RecyclerView 彼此相邻放置,没有重叠。如果您希望您的 RecyclerView 是全宽,您可以使用 ConstraintLayout 而不是您的父 LinearLayout。

您可以将 RecyclerView 限制为父级,使其充满整个屏幕。并且还把RecyclerView放在hierarchy的第一位,FrameLayout放在第二位,这样FrameLayout就会在最上面并遮挡RecyclerView。

你可以学到很多关于 ConstraintLayout here 的知识。 YouTube 上也有很多视频教程。

【讨论】:

  • 感谢您的努力!我已经尝试过你的建议,但我仍然遇到同样的问题。我必须为 recyclerview 设置一个填充,这样它一开始就不会与我的 FrameLayout 重叠。如果我这样做,recyclerview 确实会移到 FrameLayout 后面,但您仍然可以在屏幕截图中看到这条线。这就是我试图摆脱的。如果我没有正确理解你,我会更新我的代码。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-03-30
  • 2021-10-22
  • 2016-12-09
  • 2019-06-29
  • 2016-03-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多