Understanding how actually drawRect or drawing coordinates work in Android

前端 未结 5 490
猫巷女王i
猫巷女王i 2020-12-13 13:22

I am trying to draw a rectangle over a canvas and I am facing troubles to understand the in-depth of rectangle draw of Android. I\'ve read tutorials and every possible but I

5条回答
  •  醉酒成梦
    2020-12-13 13:53

    Here is my approach simple and easy

                int x = 100;  //position coordinate from left
                int y = 100;  //position coordinate from top
                int w = 100; //width of the rectangle
                int h = 100; //height of the rectangle
                drawRectangle(x, y, w, h, canvas, paint);
    

    and here is my function

        public void drawRectangle(int left, int top, int right, int bottom, Canvas canvas, Paint paint) {
        right = left + right; // width is the distance from left to right
        bottom = top + bottom; // height is the distance from top to bottom
        canvas.drawRect(left, top, right, bottom, paint);
    }
    

    it works pretty well

提交回复
热议问题