【问题标题】:Ripple effect to whole parent view by clicking on RecyclerView item通过单击 RecyclerView 项对整个父视图产生波纹效果
【发布时间】:2018-10-24 16:38:11
【问题描述】:

我有一个 CardView,其中包含 RecyclerView。当用户单击 RecyclerView 项目时,我尝试在整个 CardView(或整个 RecyclerView)上产生涟漪效应,但涟漪效应仅应用于项目。

    <android.support.v7.widget.CardView
                android:id="@+id/cardview"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:foreground="?attr/selectableItemBackground">

                <android.support.constraint.ConstraintLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <android.support.v7.widget.RecyclerView
                        android:id="@+id/list"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        app:layout_constraintBottom_toTopOf="parent"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toBottomOf="parent"/>

                </android.support.constraint.ConstraintLayout>
            </android.support.v7.widget.CardView>

【问题讨论】:

    标签: android android-recyclerview ripple


    【解决方案1】:

    将以下属性添加到您的CardView

    <android.support.v7.widget.CardView
        ...
        android:clickable="true"
        android:focusable="true"
        android:background="?android:selectableItemBackground"/>
    

    运行您的应用。它应该可以工作。

    【讨论】:

    • 您能否发布包含 CardView 和您的 RecyclerAdapterView 布局的布局。
    • 首先,你为什么要在CardView 中用ConstraintLayout 包裹你的recyclerview。这真的没有意义。删除Constraint...(包括其属性)并将我在上面发布的确切代码sn-p复制到您的代码中。请注意,您使用的是foreground,我在代码中使用了背景。
    猜你喜欢
    • 2015-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-15
    • 1970-01-01
    • 2015-04-22
    • 2019-03-23
    相关资源
    最近更新 更多