脚本宝典收集整理的这篇文章主要介绍了android图片蒙层,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
这里我们使用一个自定义view来为图片蒙层。该方法投机取巧,直接把一张有透明效果的图片直接画到原图上。tranparent.png那张图片可以换成用bITmap自己画,以后改进。先上效果图:上面是原图,下面是蒙层后的效果
public class centerImage extends ImageView {
PRivate Paint paint;
private boolean isCenterimgShow;
private Bitmap bitmap;
public void setCenterImgShow(boolean centerImgShow) {
isCenterImgShow = centerImgShow;
if (isCenterImgShow) {
bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.transparent);
invalidate();
}
}
public CenterImage(Context context) {
suPEr(context);
init();
}
public CenterImage(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public CenterImage(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
private void init() {
paint = new Paint();
}
@override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (isCenterImgShow && bitmap != null) {
//从中心点开始画
canvas.drawBitmap(bitmap, getMeasuredWidth() / 2 - bitmap.getWidth() / 2, getMeasuredHeight() / 2 - bitmap.getHeight() / 2, paint);
}
}
}
<com.epos.testrxjava.CenterImage
andROId:layout_below="@id/image"
android:id="@+id/goodsImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/dog" />
调用:
CenterImage mGoodsImg =(CenterImage)findViewById(R.id.goodsImage);
mGoodsImg.setCenterImgShow(true);
透明图片:
以上是脚本宝典为你收集整理的android图片蒙层全部内容,希望文章能够帮你解决android图片蒙层所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。