java Android RelativeLayout涟漪效应
在我看来,我希望每当用户触摸布局中的ImageView时,就会出现涟漪效应。我尝试将ImageView包装到RelativeLayout中,但没有成功。布局如下:
<RelativeLayout
xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
xmlns:tools="http://schemas.安卓.com/tools"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
tools:context="com.sample.me.TapActivity" >
<RelativeLayout
安卓:id="@+id/tap_view_frame"
安卓:layout_width="@dimen/activity_tap_image_width"
安卓:layout_height="@dimen/activity_tap_image_height"
安卓:layout_alignParentTop="true"
安卓:layout_alignParentStart="true"
安卓:layout_alignParentEnd="true"
安卓:clickable="true"
安卓:background="@drawable/ripple_view" >
<ImageView
安卓:id="@+id/tap_view"
安卓:src="@drawable/ram"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
安卓:scaleType="centerCrop"
安卓:adjustViewBounds="true"
安卓:clickable="true" />
</RelativeLayout>
<TextView
安卓:id="@+id/tap_name_textView"
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:textAppearance="?安卓:attr/textAppearanceLarge"
安卓:textColor="@color/white"
安卓:layout_marginLeft="@dimen/textview_horizontal_margin"
安卓:layout_alignParentLeft="true"
安卓:layout_above="@+id/tap_number_textView"/>
<TextView
安卓:id="@+id/tap_number_textView"
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:textAppearance="?安卓:attr/textAppearanceMedium"
安卓:textColor="@color/white"
安卓:layout_marginBottom="@dimen/textview_vertical_margin"
安卓:layout_alignLeft="@+id/tap_name_textView"
安卓:layout_alignBottom="@+id/tap_view_frame" />
<安卓.support.v7.widget.CardView
安卓:id="@+id/tap_card_view"
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:layout_marginLeft="@dimen/cardview_horizontal_margin"
安卓:layout_marginRight="@dimen/cardview_horizontal_margin"
安卓:layout_marginTop="@dimen/cardview_vertical_margin"
安卓:layout_below="@+id/tap_view_frame">
<安卓.support.v7.widget.RecyclerView
安卓:id="@+id/tap_options_recyclerview"
安卓:layout_width="match_parent"
安卓:layout_height="@dimen/cardview_tap_height" />
</安卓.support.v7.widget.CardView>
这是“ripple_view”可绘制的:
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
安卓:color="#ffa0a0a0">
<item 安卓:id="@安卓:id/mask">
<shape 安卓:shape="rectangle">
<solid 安卓:color="#ffa0a0a0"/>
</shape>
</item>
</ripple>
我还尝试添加了安卓:background=“?安卓:attr/selectableItemBackground”标记,但似乎没有帮助。有人能解释为什么纹波没有出现吗?我在自定义按钮和RecyclerView行中使用了相同的方法来启用该效果,但它不适用于RelativeLayout。理想情况下,我希望避免将第三方库用于像这样简单的事情
共 (0) 个答案