我想在android中为我的背景图片添加透明叠加层

时间:2017-09-08 10:07:26

标签: android android-layout

我想在Android中为我的背景图片添加透明叠加层,如下所示

enter image description here

我的代码

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.bykar.bykar_provider.WaitingForActivationActivity">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:contentDescription=""
        android:scaleType="centerCrop"
        android:src="@drawable/map_bg"
        tools:ignore="ContentDescription" />

    <View
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/black"
        />
</RelativeLayout>

2 个答案:

答案 0 :(得分:5)

添加背景以查看为20%不透明

<View
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#26000000"/>

如果您需要,以下是不透明度值:

100% — FF
95% — F2
90% — E6
85% — D9
80% — CC
75% — BF
70% — B3
65% — A6
60% — 99
55% — 8C
50% — 80
45% — 73
40% — 66
35% — 59
30% — 4D
25% — 40
20% — 33
15% — 26
10% — 1A
5% — 0D
0% — 00

答案 1 :(得分:2)

只需为背景颜色添加不透明度即可。在此示例中,如果您希望为黑色添加70%不透明度,请将背景颜色更改为十六进制代码#B3000000

如果您需要HEX透明度代码列表,请选中this answer