简体   繁体   English

如何在 android 工作室中的 imageview 上添加半透明覆盖并正确显示

[英]how to add semi transparent overlay on imageview in android studio and show it properlay

This is the image I am using and i want add a red transparent overlay Orignal Image这是我正在使用的图像,我想添加一个红色透明覆盖原始图像

I want add an semitransparent overlay on this image I used this code but i completly hiding the image我想在这张图片上添加一个半透明的覆盖我使用了这段代码,但我完全隐藏了这张图片

<?xml version="1.0" encoding="utf-8"?>
 <shape xmlns:android="http://schemas.android.com/apk/res/android">
   <gradient
    android:startColor="#ffcccb"
    android:centerColor="#ffcccb"
    android:endColor="#ffcccb"
    />
 </shape>

<ImageView
            android:id="@+id/backgroudImage"
            android:layout_width="match_parent"
            android:layout_height="254dp"
            android:rotation="0"
            android:scaleType="fitStart"
            android:foreground="@drawable/image_overlay"
            android:src="@drawable/backgroud"
            />

how to adjust color codes How to decrease Opacity I want to show my Image view as shown in this image This is the view i want to get如何调整颜色代码 如何降低不透明度 我想显示我的图像视图,如图所示这是我想要获得的视图

Use the below code for black:使用下面的黑色代码:

<color name="black">#000000</color>

Now if I want to use opacity then you can use the below code:现在,如果我想使用不透明度,那么您可以使用以下代码:

<color name="black">#99000000</color> <!-- 99 is for alpha and others pairs zero's are for R G B -->

And below for opacity code: and all opacity level here以下是不透明度代码:以及此处的所有不透明度级别

Hex Opacity Values十六进制不透明度值

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

also you can change alpha value on attributes layout.您也可以更改属性布局的 alpha 值。 you can write to image alpha 0.5您可以写入图像 alpha 0.5

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM