【问题标题】:RecyclerView ripple effect not workingRecyclerView 波纹效果不起作用
【发布时间】:2018-03-15 00:13:14
【问题描述】:

我正在尝试将波纹效果添加到 RecyclerView 的项目。我在网上看了一下,但找不到我需要的东西。我已尝试将 android:background 属性设置为 RecyclerView 本身并将其设置为“?android:selectableItemBackground”,但它不起作用。:

适配器模板如下所示

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/text_container"
android:layout_width="match_parent"
android:layout_height="75dp"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:orientation="vertical"

>
<TextView
    android:id="@+id/u_key"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="20dp"
    android:gravity="left"
    android:maxLines="1"
    android:paddingLeft="@dimen/u_common_text_size"
    android:paddingRight="@dimen/u_common_text_size"
    android:singleLine="true"
    android:text="Item"
    android:textColor="#808080"
    android:textSize="@dimen/u_common_text_size" />

<TextView
    android:id="@+id/u_value"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:drawablePadding="5dip"
    android:gravity="left"
    android:maxLines="1"
    android:paddingLeft="@dimen/u_common_text_size"
    android:paddingRight="@dimen/u_common_text_size"
    android:singleLine="true"
    android:text="Item"
    android:textColor="@android:color/black"
    android:textSize="@dimen/u_common_text_size" />



<View
    android:id="@+id/bottomline"
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:background="#e6e6e6"
    android:visibility="gone" />

<android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="5dp"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
         />

【问题讨论】:

    标签: android android-recyclerview android-linearlayout


    【解决方案1】:

    查看LinearLayout父视图背景,发现背景属性不正确(你忘了问号和:attr之间的android)。

    android:background="?android:attr/selectableItemBackground"
    

    【讨论】:

      【解决方案2】:

      如果你使用 ConstraintLayout,试试这个

      android:clickable="true"
      android:focusable="true"
      android:foreground="?attr/selectableItemBackground"
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-11-03
        • 2022-01-23
        • 2021-10-21
        • 1970-01-01
        • 2015-09-05
        • 2020-08-23
        • 2015-06-08
        相关资源
        最近更新 更多