gpt4 book ai didi

android - 修改android xml中背景图片的透明度

转载 作者:太空狗 更新时间:2023-10-29 15:34:55 32 4
gpt4 key购买 nike

您好,我需要在 Activity 中放置一个背景图像,并且该图像需要有点透明,因为我想在其上放置文本。如何才能做到这一点?可以直接在 xml 文件上完成吗?如果可以,怎么做?是否也可以以编程方式进行,如果可以,如何进行?你能给我举个例子吗?谢谢!

最佳答案

一个 XML 例子看起来像

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/myimage"
android:alpha=".75"/>

以编程方式,您也可以使用

int alphaAmount = 125; // some value 0-255 where 0 is fully transparent and 255 is fully opaque
myImage.setAlpha(alphaAmount);

其中 myImage 是一个 ImageView。

关于android - 修改android xml中背景图片的透明度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19252874/

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