【问题标题】:Android: How to control the Ripple effect in a RecyclerViewAndroid:如何在 RecyclerView 中控制波纹效果
【发布时间】:2016-02-12 08:04:30
【问题描述】:

我正在使用自定义 RecyclerView。在我的 RecyclerView 行中,有两项,一项是 TextView 和一个 ImageView。当我单击 TextView 时,该行项目正在显示涟漪效果。我为该布局放置了涟漪效果,因此在单击显示涟漪效果的 Textview 时。

当我单击该行右上角的图像时,涟漪效果也会显示该行的整个布局。我想控制它。

我只希望在按下 TextView/Layout 时产生涟漪效果。当我按下我想要控制波纹效果的图像时,波纹效果应该只在那个图像中

布局.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>

<RelativeLayout
    android:id="@+id/layout_subdistributorItem"
    android:layout_width="match_parent"
    android:layout_height="75dp"
    android:layout_marginLeft="15dp"
    android:layout_marginRight="-10dp"
    android:layout_marginTop="6dp"
    android:layout_alignParentRight="true"
    android:background="@drawable/list_background_with_shadow"
    android:paddingLeft="2dp">

    <com.flexiSupport.RippleView
        xmlns:ripple="http://schemas.android.com/apk/res-auto"
        android:layout_width="wrap_content"
        android:layout_height="75dp"
        ripple:rv_type="rectangle"

        >

    <ImageView
        android:id="@+id/img_activeSubdistributor"
        android:layout_width="18dp"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_marginLeft="10dp"

        android:layout_alignParentLeft="true"
        android:src="@drawable/offline"/>
    <TextView
        android:id="@+id/txt_RechargeSubdistributor"
        android:layout_width="100dp"
        android:layout_height="40dp"
        android:layout_centerVertical="true"
        android:layout_marginRight="30dp"
        android:layout_marginTop="10dp"
        android:gravity="center_horizontal|center_vertical"
        android:textColor="#fff"
        android:textSize="15dp"

        android:layout_marginBottom="10dp"
        android:layout_alignParentRight="true"
        android:background="@drawable/recharge_text"
        android:text=""/>
    <LinearLayout
        android:id="@+id/layout_subdistributor"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/img_activeSubdistributor"
        android:layout_toLeftOf="@+id/txt_RechargeSubdistributor"
        android:paddingLeft="12dp"
        android:layout_centerVertical="true"
        android:orientation="vertical">
        <TextView
            android:id="@+id/txt_subDistributorName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:textSize="15dp"
            android:textColor="@color/black"
            android:text="Subdistributor 1"
            android:maxLength="22"
            android:typeface="sans"
            android:layout_marginTop="8dp"
            android:layout_marginBottom="8dp"
            />
        <TextView
            android:id="@+id/txt_subDistributorId"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:textSize="15dp"
            android:visibility="gone"
            />

        <TextView
            android:id="@+id/txt_subDistributor_number"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:textSize="16dp"
            android:textColor="@color/black"
            android:text="99999999"
            android:maxLength="22"
            android:typeface="sans"
            android:layout_marginBottom="8dp"
            />
        </LinearLayout>
    </com.flexiSupport.RippleView>
</RelativeLayout>

这是我的布局显示为

谁能帮我控制涟漪效应

【问题讨论】:

    标签: android android-layout android-animation material-design ripple


    【解决方案1】:

    尝试将此背景赋予必须具有涟漪效果的视图,

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

    【讨论】:

      猜你喜欢
      • 2015-09-04
      • 2018-03-15
      • 2017-05-01
      • 1970-01-01
      • 2015-03-15
      • 1970-01-01
      • 1970-01-01
      • 2018-08-23
      • 2015-09-05
      相关资源
      最近更新 更多