我想在android中得到这个效果,我试过设置布局的背景但没有成功,这就像给布局的元素蒙上了一层面具。这方面的一个例子是当您点击 google play 上的按钮时,它看起来像这样:
当您单击它时,它会在蓝色按钮上放置一个 mask 。
有人可以帮助我吗?
谢谢。
我执行了以下操作,我创建了带有图像和文本的布局。
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/android" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="APP" />
</LinearLayout>
并创建框架布局
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_default"
android:clickable="true">
<include
android:layout_gravity="center_vertical"
layout="@layout/test1" />
</FrameLayout>
但只是背景改变了,图片和文字没有放置 mask 。我做错了什么吗?
最佳答案
要实现这种影响,我首先想到的是:
1. 使用图标和文本(示例中的 android 图标和 APPS
文本)创建布局(线性/相对
)。 )
2. 为两个维度将其设置为 wrap-content
。
3. 将此布局放在 FrameLayout
中。
4. 在这个 FrameLayout
中添加一个按钮并将其设置为 match-parent
,为此按钮创建一个这样的选择器并应用它作为背景:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- pressed -->
<item android:state_pressed="true"
android:drawable="@drawable/botton_shape_pressed" />
<!-- focused -->
<item android:state_focused="true"
android:drawable="@drawable/botton_shape_selected" />
<!-- default -->
<item android:drawable="@drawable/botton_shape_released" />
5. 为按下的纹理创建一个半透明的蓝色纹理。对于其他两个状态应用完全透明的纹理。这将导致面具影响您寻找。
关于android - 单击时 android 组件的掩码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16380141/