Android之遮罩功能的实现
上午有个哥们问我android有没有获取圆形图片的方法,就是要把正方形的图片变成圆形的来显示。最近也有再搞flash,所以第一反应就是遮罩,android里面自己也没搞过。google搜索“android mask“挺多资料的,这里把例子与大家分享。先上效果图:[attach]250312[/attach]
好了现在开始代码部分,这里使用了自定义组件以及自定义属性的方式来进行编码[align=center]。[/align]
1、添加资源文件:attrs.xml[code]<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="MaskImage">
<!-- Identifier for the image that represents the Imageview's content. -->
<attr name="image" format="reference" />
<!-- crop Imageview's content same as mask -->
<attr name="mask" format="reference" />
</declare-styleable>
</resources>
[/code]2、创建自定义组件MaskImage.java[code]package com.xzw.mask.widget;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;