透明度-如何在Android上使图像透明?
我正在使用线性布局和框架布局。 在线性布局中,我保留图像作为背景,在框架布局中,保留imageView。 在那个imageView中,我给出一个图像。
现在,我想使第二个图像(在imageView中)透明。 我怎样才能做到这一点?
khan asked 2019-11-03T09:11:03Z
12个解决方案
123 votes
试试这个:
ImageView myImage = (ImageView) findViewById(R.id.myImage);
myImage.setAlpha(127); //value: [0-255]. Where 0 is fully transparent and 255 is fully opaque.
注意:不建议使用setAlpha(int),而建议使用setAlpha(float),其中0是完全透明的,而1是完全不透明的。 像这样使用:myImage.setAlpha(0.5f)
Rubycon answered 2019-11-03T09:11:22Z
83 votes
android:alpha使用XML执行此操作:
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/blah"
android:alpha=".75"/>
Eric an