<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">长话短说,为了是ImageView 整个控件变得透明或者半透明, 很多小伙伴会设置mImageView.setAlpha()这个函数</span>
但是ImageView 有三个方法,
一是, 参数为int类型
titleHeadIv.setAlpha(0~255);
二是,参数为float类型
titleHeadIv.setAlpha(0f~1f);
三是,setImageAlpha(int),这个方法是较高api的, 不做使用
当我们使用第一个方法时, 对ImageView 是无效的, 不管设置什么值都显示不出效果。当时被这个方法坑死,怎么设置都无法使用。
当使用第二个方法setAlpha(0.5f),参数必须为0~1 的小数, 大于1就表示100%的透明度,
当设置参数为0.5 的时候,透明度是一半。成功解决ImageView的透明效果。
titleHeadIv.setAlpha(0.5f);
若想改变其他带有background 的控件也可以使用setAlpha方法 :
如: 半透明效果
Drawable frontd = titleView.getBackground();
float f = 0.5;
frontd.setAlpha