为棒棒糖和棒棒糖前添加涟漪效应到回收者列表视图



我正试图将涟漪效应添加到RecyclerView的项目。我在网上看了一下,但找不到我需要的东西。我已经尝试过android:背景属性到RecyclerView本身,并将其设置为"?android:attr/selectableItemBackground"但是没有工作。

适配器模板是这样的

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:clickable="true"
    android:background="?android:attr/selectableItemBackground"
    xmlns:custom="http://schemas.android.com/apk/res-auto">

    <LinearLayout
        android:id="@+id/anLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
        android:weightSum="4">
        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_weight="3">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
            <com.kahoindia.dev.customclasses.KaHOTextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:singleLine="true"
                style="@style/kaho_listview_label_heading"
                android:id="@+id/txtTitle"
                custom:CustomTextViewFont="@string/kaho_segoeui_semi_light_font"/>
            </LinearLayout>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

            <com.kahoindia.dev.customclasses.KaHOTextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:ellipsize="marquee"
                android:maxLines="2"
                android:id="@+id/txtDetail"
                style="@style/kaho_content_small_textview_style"
                custom:CustomTextViewFont="@string/kaho_segoeui_regular_font"/>
             </LinearLayout>
        </LinearLayout>
        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:layout_marginTop="7dp"
            android:layout_gravity="center"
            android:gravity="right">
            <com.kahoindia.dev.customclasses.KaHOTextView
                android:id="@+id/txtDate"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                style="@style/kaho_content_small_textview_style"
                custom:CustomTextViewFont="@string/kaho_segoeui_regular_font"
                />
        </LinearLayout>
        <ProgressBar
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/progressBar"
            android:indeterminate="true"
            android:visibility="gone"
            style="@android:style/Widget.Holo.ProgressBar"
            android:layout_gravity="center_horizontal"/>
    </LinearLayout>
</LinearLayout>

请帮帮我

使用这个库,它为棒棒糖和预棒棒糖版本提供支持。为了更好地理解实现,下面的链接显示。

https://github.com/traex/RippleEffect

这个库的编译行

dependencies {
compile 'com.github.traex.rippleeffect:library:1.3'
}

在可绘制文件夹中添加名为"ripple_effect"的新xml文件,并添加:

 <?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="@color/ripple_color">
    <item android:id="@android:id/mask">
        <shape android:shape="oval">
            <solid android:color="@color/button_background_color" />
        </shape>
    </item>
</ripple>

你可以在xml中实现,比如在项目的背景中,或者在java中实现,比如setResourceBackground,你也可以使用标准的android实现:

android:background="?attr/selectableItemBackground"

最新更新