Understanding how actually drawRect or drawing coordinates work in Android

前端 未结 5 494
猫巷女王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:57

    X runs horizontally, from left to right. Y runs vertically, from top to bottom. It's exactly the same as on your graphics. So (0/0) is at top left.

    When you go "up" Y will of course get smaller, as it grows from top to bottom.

    You have to pay attention to laying out elements like ListViews, these will give a partial (or new, you cannot tell) canvas to your views that are drawn. These views will have 0x0 at their own top/left position. If you need the absolute you have to subsequently call View.getLocationOnScreen() and calculate offsets yourself.

提交回复
热议问题