在另一个背景中创建背景

时间:2011-03-08 18:39:42

标签: android

我想创建以下内容:

我正在使用相对布局&指定背景颜色“蓝色”。 我想从边距中绘制另一种带有空间的背景颜色(黑色)。另外,我想要黑色矩形的圆角(不在图片上)

请提供示例代码。

enter image description here

1 个答案:

答案 0 :(得分:1)

我提供此代码=

public class DrawDemo extends Activity {
    DemoView demoview;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        super.onCreate(savedInstanceState);
        demoview = new DemoView(this);
        setContentView(demoview);
    }
    private class DemoView extends View{
        public DemoView(Context context){
            super(context);
        }

        @Override 
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);
            Paint paint = new Paint();
            paint.setStyle(Paint.Style.FILL);
            paint.setColor(Color.BLUE);
            canvas.drawPaint(paint);
            paint.setColor(Color.BLACK);
            paint.setAntiAlias(true);
            canvas.drawRect(16, 16, getWidth()-16, getHeight()-16, paint);

        }
    }
}

最好,:))