这是我的代码 BackDeckView
public class BackDeckView extends View
{
/*Others Constructor includeed*/
private void initView(Context context)
{
setBackground(new BaseDrawable(getResources().getDrawable(R.drawable.tarotback)));
}
//onDraw
}
BaseDrawable是_
public class BaseDrawable extends Drawable
{
public Drawable icon;
private Paint paint;
public BaseDrawable(Drawable icon)
{
this.icon = icon;
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(android.R.color.holo_green_light);
}
@Override
public void draw(Canvas canvas)
{
Rect bounds = getBounds();
canvas.drawRoundRect(0,0,canvas.getWidth(),canvas.getHeight(),20f,20f,paint);
icon.setBounds(bounds);
icon.draw(canvas);
invalidateSelf();
}
//setAlpha
//setColorFilter
@Override
public int getOpacity()
{
return PixelFormat.TRANSLUCENT;
}
}
结果就像这张照片
我尝试从BackDeckView覆盖画布以进行roundedrect但它只显示黑色页面而且我也丢失了背景位图