private void init(){
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
roundRect = new RectF(0, 0, getWidth() , getHeight());
radius = 40;
mPorterDuffXfermode = new PorterDuffXfermode(PorterDuff.Mode.SRC_IN) ;
}
protected void onDraw(Canvas canvas) {
int sc = canvas.saveLayer(0, 0, getWidth() , getHeight(), null,
Canvas.MATRIX_SAVE_FLAG |
Canvas.CLIP_SAVE_FLAG |
Canvas.HAS_ALPHA_LAYER_SAVE_FLAG |
Canvas.FULL_COLOR_LAYER_SAVE_FLAG |
Canvas.CLIP_TO_LAYER_SAVE_FLAG);
roundRect.set(0, 0, getWidth(), getHeight());
canvas.drawRoundRect(roundRect, radius, radius, paint);
reflectSetXfermod();
super.onDraw(canvas);
canvas.restoreToCount(sc);
}
private void reflectSetXfermod(){
Drawable drawable = getDrawable();
if(drawable == null){
return;
}
Class bsClass = null;
Class[] innerClasses = BitmapDrawable.class.getDeclaredClasses();
for(Class innerClass :innerClasses)
{
String name = innerClass.getName();
System.out.println("-----innerClass---"+name);
if(name.equals("android.graphics.drawable.BitmapDrawable$BitmapState"))
{
bsClass = innerClass;
}
}
if(bsClass!= null){
try {
Field mPaintField = bsClass.getDeclaredField("mPaint");
mPaintField.setAccessible(true);
ConstantState constantState = ((BitmapDrawable)drawable).getConstantState();
Paint paint = (Paint)mPaintField.get(constantState);
paint.setXfermode(mPorterDuffXfermode);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchFieldException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有