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

时间:2013-10-08 16:09:38

标签: android background-image transparency

嗨我需要在活动中放置一个背景图片,这个图片需要有点透明,因为我想把文字放在上面。如何才能做到这一点? 可以直接在xml文件上完成,如果是,如何? 它是否也可以以编程方式进行,如果是,如何? 你能告诉我一个例子吗? 三江源!

3 个答案:

答案 0 :(得分:13)

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。

答案 1 :(得分:0)

答案 2 :(得分:0)

你应该使用这个:     yourview.getBckground().setAlpha(INTEGER_VALUE (more than 100));