本文介绍了圈画在画布上没有屏幕匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提请圈在屏幕中央,但我发现这样的:

I want to draw circle in center of screen, but I'm getting something like this:

我用这个code画这个圈。

I'm using this code to draw this circle.

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Display display = getWindowManager().getDefaultDisplay();
    int width = display.getWidth();
    int height = display.getHeight();

    Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444);

    Canvas c = new Canvas(bmp);

    RectF rect = new RectF(0,0,width,width);
    drawCircle(rect, c, width, height);
    ImageView img = (ImageView) findViewById(R.id.imageView1);
    img.setImageBitmap(bmp);
    img.setScaleType(ScaleType.FIT_CENTER);


}

private void drawCircle(RectF rect, Canvas c, int width, int height) {
    Paint paint = new Paint();
    paint.setARGB(255, 255 , 10, 21);
    paint.setStrokeWidth(10);
    paint.setAntiAlias(true);
    paint.setStrokeCap(Paint.Cap.BUTT);
    paint.setStyle(Paint.Style.STROKE);
    int radius;
    if(width < height)
        radius = width/2;
    else
        radius = height/2;
    c.drawCircle(width/2, height/2, radius, paint);
}

我不明白为什么它的切割边,即使我用屏幕尺寸来绘制,因此它应该完全适合它。

I don't understand why it's cut at sides even though I use size of screen to draw it, so it should perfectly fit it.

推荐答案

您没有考虑行(strokeWidth)的厚度。你画了一个圈假设它有0的厚度,因此,实际的圆是触摸屏幕的边缘,但因为你使用了​​厚厚的画笔,一些油漆泄露过去的边缘。

You didn't account for the thickness of the line (strokeWidth). You drew a circle assuming it had 0 thickness, so the "actual" circle IS touching the edges of the screen, but since you used a thick paintbrush, some of the paint leaked past the edge.

这篇关于圈画在画布上没有屏幕匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 08:02