android - 在 Android Studio 中创建叠加层
解决方案
使用alpha
属性
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:background="#FFFF33"
android:layout_width="match_parent"
android:layout_height="200dp">
<TextView
android:textAlignment="textEnd"
android:text="Sample Text View Sample Text View Sample Text View"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<RelativeLayout
android:alpha="0.5"
android:background="@color/colorPrimary"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_width="100dp"
android:layout_height="200dp">
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
输出将像
*********** EDITED AS PER OP'S REQUIREMENT
***********
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:background="#FFFF33"
android:layout_width="match_parent"
android:layout_height="200dp">
</LinearLayout>
<RelativeLayout
android:alpha="0.5"
android:background="@color/colorPrimary"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_width="100dp"
android:layout_height="200dp">
</RelativeLayout>
<TextView
android:textAlignment="textEnd"
android:text="Sample Text View Sample Text View Sample Text View"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
</RelativeLayout>
推荐阅读
- vue.js - 从 base.com/some/other 路由时出现 nuxt 链接问题
- vba - 在 Outlook 中搜索关键字的邮件
- excel - 如何在基于 32 位和 64 位 ODBC 的机器之间来回切换?
- java - 正确初始化 DL4J 中较大尺寸图像的 ImageRecordReader(长高、长宽、长通道)
- tcp - TCP和UDP的不同应用
- html - 如何在 html/html5 中显示图像和音频?
- ruby - Jekyll:错误数量的参数(给定 2,预期 1)(ArgumentError)
- amazon-cloudformation - AWS Cloudformation 错误:策略具有无效资源
- android - Android - 查看同一活动的所有传感器值
- swift - 处理 SwiftUI 组合应用程序中的 Firebase 身份验证错误