如何通过按下android中的按钮绘制圆圈

时间:2016-12-09 16:41:53

标签: java android button draw

我想在用户按下按钮时绘制小圆圈。 并且这些圈子按某种顺序排列,一个在另一个圈子上,所以你看不到你制作了多少个圈子。

Button draw = (Button)findViewById(R.id.buttonOne);
draw.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        new MyView(MainActivity.this);
    }
});

public class MyView extends View {
   public MyView(Context context) {
       super(context);
       // TODO Auto-generated constructor stub
   }
}


@Override
protected void onDraw(Canvas canvas) {
    // TODO Auto-generated method stub
    super.onDraw(canvas);
    int x = getWidth();
    int y = getHeight();
    int radius;
    radius = 100;
    Paint paint = new Paint();
    paint.setStyle(Paint.Style.FILL);
    paint.setColor(Color.WHITE);
    canvas.drawPaint(paint);
    // Use Color.parseColor to define HTML colors
    paint.setColor(Color.parseColor("#CD5C5C"));
    canvas.drawCircle(x / 2, y / 2, radius, paint);

}

0 个答案:

没有答案