Android RelativeLayout Ripple效果

时间:2016-01-30 23:16:06

标签: java android android-relativelayout rippledrawable

在我看来,每当用户触摸布局中的ImageView时,我都希望出现涟漪效果。我已经尝试将ImageView包装在RelativeLayout中,但它还没有工作。这是布局:

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.sample.me.TapActivity" >

<RelativeLayout
    android:id="@+id/tap_view_frame"
    android:layout_width="@dimen/activity_tap_image_width"
    android:layout_height="@dimen/activity_tap_image_height"
    android:layout_alignParentTop="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentEnd="true"
    android:clickable="true"
    android:background="@drawable/ripple_view" >

    <ImageView
        android:id="@+id/tap_view"
        android:src="@drawable/ram"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="centerCrop"
        android:adjustViewBounds="true"
        android:clickable="true" />

</RelativeLayout>

<TextView
    android:id="@+id/tap_name_textView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:textColor="@color/white"
    android:layout_marginLeft="@dimen/textview_horizontal_margin"
    android:layout_alignParentLeft="true"
    android:layout_above="@+id/tap_number_textView"/>

<TextView
    android:id="@+id/tap_number_textView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:textColor="@color/white"
    android:layout_marginBottom="@dimen/textview_vertical_margin"
    android:layout_alignLeft="@+id/tap_name_textView"
    android:layout_alignBottom="@+id/tap_view_frame" />

<android.support.v7.widget.CardView
    android:id="@+id/tap_card_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="@dimen/cardview_horizontal_margin"
    android:layout_marginRight="@dimen/cardview_horizontal_margin"
    android:layout_marginTop="@dimen/cardview_vertical_margin"
    android:layout_below="@+id/tap_view_frame">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/tap_options_recyclerview"
        android:layout_width="match_parent"
        android:layout_height="@dimen/cardview_tap_height" />

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

这是&#34; ripple_view&#34;绘制:

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

我也试过添加android:background =&#34;?android:attr / selectableItemBackground&#34;标签,但似乎没有帮助。谁能解释为什么波纹没有出现?我使用相同的方法在我的自定义按钮和RecyclerView行中启用效果,但它不适用于RelativeLayout。理想情况下,我想避免使用第三方库来处理这么简单的事情。

0 个答案:

没有答案