开发者

Draw circle in android [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so 开发者_Go百科that it can be reopened, visit the help center. Closed 9 years ago.

How can I draw circle between two points using the Android SDK?


Create A bitmap then draw on its canvas and then add this bitmap to an imageview or button or whatever you want.

Create A bitmap:

    Bitmap bmp = Bitmap.createBitmap(width, height, config);

Draw on the bitmap canvas

    Canvas c = new Canvas(bmp);
    c.drawCircle(cx, cy, radius, paint)

setting to imageview

    img.setBackgroundDrawable(new BitmapDrawable(bmp));


You don't necessarily need to create a bitmap manual.

For example if you use a SurfaceView, in the SurfaceView class you are able to draw a circle:

public class Circle extends SurfaceView implements SurfaceHolder.Callback {
private Paint paint;

    public void onDraw(Canvas canvas) {
        canvas.drawCircle(x, y, radius, this.paint);
    }
}

Then you can add the SurfaceView to your Activity class like:

public class MovingCircle extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(new Circle());
    }

}

I hope this will also help you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜