且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

材质波纹效果被布局中的其他视图隐藏

更新时间:2023-11-17 14:06:59

我遇到了完全相同的问题,并使用以下线程解决了该问题: 问题预览:

解决之前:

解决后:

说明:

无边界按钮会将内容绘制在最接近的背景上.您的按钮与ImageView之间可能没有背景,因此它绘制在ImageView下方."

"Borderless buttons draw their content on the closest background. Your button might not be having background between itself and the ImageView, so it draws underneath the ImageView."

解决方案:

在某些包含按钮的布局上(在ImageView之下)使用透明背景(android:background="@android:color/transparent").这将决定波纹效果的最大界限是什么."

"Use a transparent background (android:background="@android:color/transparent") on some layout containing the button (beneath the ImageView). This will dictate what the maximum bounds of the ripple effect is."

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
                ...>

    <!-- Your background ImageView -->
    <ImageView
        android:id="@+id/drawerBackgroundImageView"
        android:src="@drawable/drawer_background"
        ... />

        <!-- ... -->

    <!-- HERE, you need a container for the button with the transparent
         background. Let's say you'll use a FrameLayout -->
    <FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent">

        <!-- Maybe more items --> 

        <!-- Button with borderless ripple effect -->
        <ImageButton
            android:id="@+id/drawerLogoutButton"
            android:background="?selectableItemBackgroundBorderless"
            ... />

    </FrameLayout>

</FrameLayout>

希望有帮助.