子视图上的波及效应无法工作。

3
这是布局代码。
    <RelativeLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
xmlns:android="http://schemas.android.com/apk/res/android" >
<TextView
    android:id="@+id/save"
    android:layout_centerVertical="true"
    android:text="@string/save"
    android:textSize="@dimen/text_size"
    android:textColor="@color/white"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />
<ImageView
    android:layout_toRightOf="@+id/save"
    android:layout_centerVertical="true"
    android:src="@drawable/ic_right_arrow"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" /></RelativeLayout>

波纹效果仅在子视图之外生效。如何实现波纹效果影响整个布局,包括子视图?


1
同时也将它们的"android:background="?android:attr/selectableItemBackground""属性设置为相同。 - ak sacha
所以您希望单击子视图时它们具有各自的涟漪效果,而在单击任何内容时RelativeLayout也具有涟漪效果? - Rachit
@Rachit 不,我只想让整个布局产生一个涟漪效果。 - Mithun Kumar
那么只需设置android:background="?android:attr/selectableItemBackground"即可。你遇到了什么问题? - Rachit
1个回答

7
您可以尝试更改


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

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

这将使涟漪出现在RelativeLayout的顶部,因此所有的ChildViews也会被涟漪覆盖。
区别在于:

Click on two RelativeLayouts

在顶部RelativeLayout中,背景被设置为selectableItemBackground,而在底部,前景被设置为selectableItemBackground。

谢谢,android:foreground="?android:attr/selectableItemBackground" 可以在整个布局中产生单个涟漪效果。 - Mithun Kumar

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接