1

I try to create a stroke for my view and it work well if the left and top is 0. After I change the left rect, the left edge stroke is bigger than normal. Example, I set the left to 10

public class SimpleView  extends View {
    Paint paint = new Paint();
    RectF bodyRect = new RectF();
    ...

    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        bodyRect = new RectF(10, 0, getWidth(), getHeight());

        paint.setColor(Color.WHITE);
        paint.setStrokeWidth(20);
        paint.setStyle(Paint.Style.STROKE);
        canvas.drawRect(bodyRect,paint);
    }
}

xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    ...
    android:background="#000">

    <...SimpleView
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:layout_margin="50dp"
        android:background="#f00" />

</LinearLayout>

the left stroke is bigger

enter image description here

If I use the

bodyRect = new RectF(0, 0, getWidth(), getHeight());

enter image description here
the result look good

Any help would be great appreciated.

Linh
  • 57,942
  • 23
  • 262
  • 279

1 Answers1

0

I just find the solution. It is not bigger. Stroke by default don't display FULL
If I do like this, whole stroke can display

bodyRect = new RectF(10, 10, getWidth()-10, getHeight()-10); // 10 = strokeWidth/2

enter image description here

Linh
  • 57,942
  • 23
  • 262
  • 279