Android 单击已具有背景XML的相对布局时应用涟漪效应

Android 单击已具有背景XML的相对布局时应用涟漪效应,android,Android,我试图在点击一个已经有背景XML的相对布局时实现连锁反应。但是我该怎么做呢?如果我想将涟漪效应添加到相对布局中,那么我必须将背景XML中的标记更改为,但是当我这样做时,我会丢失为相对布局指定的圆角半径和纯色 以下是相对布局的代码: <RelativeLayout android:layout_width="400dp" android:layout_height="100dp" android:background="@drawable/roundedc

我试图在点击一个已经有背景XML的相对布局时实现连锁反应。但是我该怎么做呢?如果我想将涟漪效应添加到相对布局中,那么我必须将背景XML中的标记更改为
,但是当我这样做时,我会丢失为相对布局指定的圆角半径和纯色

以下是相对布局的代码:

<RelativeLayout
      android:layout_width="400dp"
      android:layout_height="100dp"
      android:background="@drawable/roundedcorners">
</RelativeLayout>

下面是背景XML“roundedcorners”中的代码



我查找了相同的帖子,但没有找到,因为这些帖子只是关于如何实现涟漪效应的信息,而没有关于如何合并和使用涟漪效应、缩放或形状标记的信息

解决这个问题的方法是使用特殊的屏蔽层。通过将
android:id
值设置为
@android:id/mask
,可以指定遮罩层

对于下面的示例,可以将遮罩设置为与要遮罩的视图相同的大小/形状,然后纹波将仅显示该区域。这样做:

    <?xml version="1.0" encoding="utf-8"?>
    <ripple xmlns:android="http://schemas.android.com/apk/res/android"
        android:color="?android:attr/colorControlHighlight">
        <item android:id="@android:id/mask">
           <shape 
              android:shape="rectangle">
              <solid android:color="#000000"/>
               <corners
                 android:radius="25dp"/>
            </shape>
        </item>
        <item android:drawable="@drawable/rounded_corners" />
    </ripple>


现在您可以将其设置为您的
android:background

非常感谢!这对我帮助很大!
    <?xml version="1.0" encoding="utf-8"?>
    <ripple xmlns:android="http://schemas.android.com/apk/res/android"
        android:color="?android:attr/colorControlHighlight">
        <item android:id="@android:id/mask">
           <shape 
              android:shape="rectangle">
              <solid android:color="#000000"/>
               <corners
                 android:radius="25dp"/>
            </shape>
        </item>
        <item android:drawable="@drawable/rounded_corners" />
    </ripple>