xml - Android和设置alpha(imageview alpha
是否真的没有与setAlpha(int)相对应的XML属性?
如果没有,有什么替代品?
9个解决方案
222 votes
它比其他响应更容易。有一个xml值android:alpha="1.0",它取两倍的值。
android:alpha="1.0"那是看不见的
android:alpha="1.0"透视
android:alpha="1.0"完全可见
这就是它的工作原理。
jfcogato answered 2019-07-11T01:18:23Z
147 votes
不,没有,看看"相关的XML属性" ImageView.setAlpha(int)文档中缺少section。 另一种方法是使用View.setAlpha(float),它的XML对应物是android:alpha.它的范围是0.0到1.0而不是0到255.使用它,例如 喜欢
但是,后者仅在API级别11之后可用。
sschuberth answered 2019-07-11T01:17:33Z
46 votes
我不确定XML,但您可以通过以下方式执行代码。
ImageView myImageView = new ImageView(this);
myImageView.setAlpha(xxx);
在API 11之前:
范围是0到255(含),0是透明的ÿ