【问题标题】:Ripple effect not working for nested recycler view涟漪效应不适用于嵌套回收器视图
【发布时间】:2020-12-11 14:14:27
【问题描述】:

我有一个回收站视图,每个项目都包含另一个回收站视图。当用户点击它时,我想要父回收器视图项目的涟漪。以下代码在我点击文本视图 (@id/friend_name) 时会产生涟漪,但在点击friend_expenses 回收器视图时不会。

当用户触摸此项目的任何位置时,我想要一个涟漪 (@id/parent_recycler_view_item_layout)。请帮忙。

父回收者查看项目:

<androidx.constraintlayout.widget.ConstraintLayout
    android:id="@+id/parent_recycler_view_item_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?selectableItemBackground"
    android:clickable="true"
    android:focusable="true">

    <TextView
        android:id="@+id/friend_name"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="pare"
        app:layout_constraintTop_toTopOf="parent" />

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/friend_expenses"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/friend_name"
        tools:itemCount="3"
        tools:listitem="@layout/group_friend_expense_item" />
</androidx.constraintlayout.widget.ConstraintLayout>

儿童回收站查看项目(@layout/group_friend_expense_item):

<TextView
    android:id="@+id/friend_expense"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

【问题讨论】:

    标签: android android-recyclerview


    【解决方案1】:

    如果您想要涟漪效果,只需将其添加到目标 View

    android:foreground="?selectableItemBackground"    //better in foreground not background
    

    而且android:clickable="true" 也可能需要(如果你没有在上面设置任何Listener)。

    【讨论】:

    【解决方案2】:

    我通过向 parent_recycler_view_item_layout 添加一个覆盖整个布局的视图解决了这个问题。我给它一个 1dp 的高度,并将 selectableItemBackground 添​​加到这个视图中。

    【讨论】:

      猜你喜欢
      • 2015-11-19
      • 1970-01-01
      • 1970-01-01
      • 2016-04-25
      • 2020-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多