Android ImageView覆盖了重叠按钮';s涟漪效应

Android ImageView覆盖了重叠按钮';s涟漪效应,android,material-design,Android,Material Design,我有一个ImageView作为Relativelayout的背景,上面有一个刷新按钮。按钮下面的ImageView覆盖了按钮的涟漪效应。我尝试过框架布局等,但似乎没有任何帮助 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/nav_dra

我有一个ImageView作为Relativelayout的背景,上面有一个刷新按钮。按钮下面的ImageView覆盖了按钮的涟漪效应。我尝试过框架布局等,但似乎没有任何帮助

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/nav_drawer"
    android:layout_width="315dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="@color/sidebar_bg_color"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/imageView4"
        android:layout_width="fill_parent"
        android:layout_height="165dp"
        android:layout_alignParentTop="true"
        android:src="@drawable/device_bg" />

    <LinearLayout
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:layout_alignParentEnd="true"
        android:layout_alignParentTop="true"
        android:background="?android:attr/selectableItemBackgroundBorderless"
        android:clickable="true"
        android:focusable="true"
        android:gravity="center"
        android:orientation="vertical">

        <ImageView
            android:id="@+id/imageView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/sidebar_refresh" />
    </LinearLayout>

</RelativeLayout>


使用
SelectableItemBackgroundless
,您可以这样做:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/nav_drawer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="@android:color/holo_green_light"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/imageView4"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:scaleType="fitXY"
        android:src="@drawable/device_bg" />

    <ImageView
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:layout_alignParentEnd="true"
        android:layout_alignParentTop="true"
        android:src="@drawable/sidebar_refresh" />

    <LinearLayout
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:layout_alignParentEnd="true"
        android:layout_alignParentTop="true">
        <FrameLayout
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:padding="7dp"
            android:background="@android:color/transparent">
            <ImageView
                android:id="@+id/imageView3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:clickable="true"
                android:src="@drawable/sidebar_refresh"
                android:alpha="0"
                android:background="?attr/selectableItemBackgroundBorderless"/>
        </FrameLayout>
    </LinearLayout>

</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/nav_drawer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="@android:color/holo_green_light"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/imageView4"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:scaleType="fitXY"
        android:src="@drawable/device_bg" />

    <ImageView
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:layout_alignParentEnd="true"
        android:layout_alignParentTop="true"
        android:src="@drawable/sidebar_refresh" />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_alignParentTop="true">
        <FrameLayout
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:background="@android:color/transparent">
            <ImageView
                android:id="@+id/imageView3"
                android:layout_width="48dp"
                android:layout_height="48dp"
                android:clickable="true"
                android:src="@drawable/ripple" />
        </FrameLayout>
    </LinearLayout>

</RelativeLayout>
据我观察,它会产生与
selectableItemBackgroundBorderless
do一样的连锁反应(除了没有溢出连锁反应),因此没有理由坚持使用默认值
SelectableItemBackgrounderless

使用此
ripple.xml
,执行以下操作:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/nav_drawer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="@android:color/holo_green_light"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/imageView4"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:scaleType="fitXY"
        android:src="@drawable/device_bg" />

    <ImageView
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:layout_alignParentEnd="true"
        android:layout_alignParentTop="true"
        android:src="@drawable/sidebar_refresh" />

    <LinearLayout
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:layout_alignParentEnd="true"
        android:layout_alignParentTop="true">
        <FrameLayout
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:padding="7dp"
            android:background="@android:color/transparent">
            <ImageView
                android:id="@+id/imageView3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:clickable="true"
                android:src="@drawable/sidebar_refresh"
                android:alpha="0"
                android:background="?attr/selectableItemBackgroundBorderless"/>
        </FrameLayout>
    </LinearLayout>

</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/nav_drawer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="@android:color/holo_green_light"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/imageView4"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:scaleType="fitXY"
        android:src="@drawable/device_bg" />

    <ImageView
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:layout_alignParentEnd="true"
        android:layout_alignParentTop="true"
        android:src="@drawable/sidebar_refresh" />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_alignParentTop="true">
        <FrameLayout
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:background="@android:color/transparent">
            <ImageView
                android:id="@+id/imageView3"
                android:layout_width="48dp"
                android:layout_height="48dp"
                android:clickable="true"
                android:src="@drawable/ripple" />
        </FrameLayout>
    </LinearLayout>

</RelativeLayout>

唯一更改的是
LinearLayout
零件。没有更多的硬编码填充和阿尔法图像。唯一的小问题是点击角点仍然会引发连锁反应。我找到了这个,但还没试过


即使图像是不透明的,上述两种方法也能起作用。

将ripple xml的代码和触发ripple的代码发布到哪里effect@prem我没有使用ripple.xml,我使用的是Android内置的ripple效应,使用的是Android:background=“?Android:attr/selectableItemBackgroundBorderless”,在我将ImageView添加到它下面之前,它可以正常工作。