gpt4 book ai didi

android - RippleDrawable 不在 View 上绘制

转载 作者:行者123 更新时间:2023-11-29 14:37:15 26 4
gpt4 key购买 nike

我有一个布局,上面有一个 KenBurnsView 和一个 ImageView(只是一个切换按钮)。当我单击按钮时,会生成一个 Ripple,但绘制在 KenBurnsView 下方。

以前,当我用 ImageView 代替 KenBurnsView 时,波纹被绘制在顶部的 ImageView 之上。

这是我的布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background"
android:clickable="true"
android:orientation="vertical">


<RelativeLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="@dimen/nav_drawer_header_height">

<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.flaviofaria.kenburnsview.KenBurnsView
android:id="@+id/header_cover"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/cover_1" />

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
android:id="@+id/header_toggle"
android:layout_width="50dp"
android:layout_height="30dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dp"
android:padding="10dp"
android:src="@drawable/toggle_down" />

</RelativeLayout>

</FrameLayout>

</RelativeLayout>

<RelativeLayout
android:id="@+id/nav_toggle_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></RelativeLayout>

</LinearLayout>

这是我的波纹可绘制 XML:

<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@android:color/white"
android:drawSelectorOnTop="true"> <!-- ripple color -->

</ripple>

这就是我添加涟漪的方式:

toggle.setBackground(getResources().getDrawable(R.drawable.ripple));

Ripple 在 KenBurnsView 下方的问题是什么?当用 ImageView 代替 KenBurnsView 时,它曾经完美地工作吗?

最佳答案

无限的涟漪被转换到祖先 View 的第一个可用背景上。从托管涟漪的 ImageView 中追踪 View 层次结构,您会发现第一个可用背景位于 LinearLayout 上,标识符为 drawer

如果您在包含您的 ImageViewRelativeLayout 上设置透明背景,第一个可用背景将呈现在同级 View 上方,您将获得所需的效果.

旁注,RelativeLayout 应替换为 FrameLayout,这将提供相同的效果,但布局传递成本较低。

关于android - RippleDrawable 不在 View 上绘制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30261947/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com