如何在android中绘制一个圆圈?

时间:2014-02-11 09:54:22

标签: android android-canvas

我正在使用此方法在我的应用中绘制一个圆圈:

public void drawCircle(){       
    paint.setColor(Color.rgb(52, 73, 94));
    paint.setFlags(Paint.ANTI_ALIAS_FLAG);      
    canvas.drawCircle(100, 200, 60, paint);     
}

问题是圆圈呈椭圆形并带有像素化边缘 我使用了ANTI_ALIAS_FLAG,但它不起作用。
如何画一个边缘光滑的圆圈?

EDIT 我使用游戏框架。从这本书:http://www.amazon.com/Beginning-Android-Games-Mario-Zechner/dp/1430246774

2 个答案:

答案 0 :(得分:0)

试试这个

 @Override
    public void onDraw(Canvas canvas){
    super.onDraw(canvas);

     canvas.drawCircle(x, y, radius, paint);

}

有关绘制自定义视图的更好参考,请查看官方Android documentation

祝你好运!

答案 1 :(得分:0)

@Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(new MyView(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);
        }
     }