2

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

4

3 回答 3

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。

于 2013-10-08T16:47:04.167 回答
0

you should use this: yourview.getBckground().setAlpha(INTEGER_VALUE (more than 100));

于 2015-01-11T08:12:44.627 回答
0

你必须使用android:alpha

http://developer.android.com/reference/android/view/View.html#attr_android:alpha

于 2013-10-08T16:13:36.227 回答