了解如何实际的drawRect或图形中的Andr​​oid协调工作 [英] Understanding how actually drawRect or drawing coordinates work in Android

查看:105
本文介绍了了解如何实际的drawRect或图形中的Andr​​oid协调工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想绘制一个矩形在一个画布,我面临的困难,了解深入的Andr​​oid的矩形平局。我读过的教程和每一个可能的,但我坚持。

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 am stuck.

下面的图片中,红色矩形是我的目标。

Here in the image , the red rectangle is my target.

不论任何矩形尺寸的我需要绘制红色矩形位上方的基座,并在矩形的中间。我在这里面临的是了解在X的最糟糕的噩梦,Y宽度和高度协调。

Irrespective of any rectangle size I need to draw the red rectangle bit above the base and in the middle of the rectangle. The worst nightmare I am facing here is understanding the X,Y Width and Height coordinates.

谁能解释这是如何工作的数学,有时我们上去,Y达到非常小的,但宽度相同的坐标都较高。而且我从来没有能够证明红光内部矩形properly.In一些屏幕效果很好在其他一些失败。红色矩形有时会父矩形的。

Can anyone explain how that math works, sometime we go up , Y reaches to very small but same width coordinates are higher. And I am never able to justify red inner rectangle properly.In some screen it works well in some other it fails. The red rectangle sometimes come out of the parent rectangle.

议程是了解如何协调工作,确保内部红色矩形的完整性

这将是巨大的,得到基于一个例子进行说明。我使用 -

It'll be great to get an explanation based on an example. I am using-

void drawRect(float left, float top, float right, float bottom, Paint paint)

要绘制矩形

推荐答案

X运行水平,从左至右。 Ý垂直运行时,从顶部到底部。这是完全一样的图形。所以(0/0)位于左上角。

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.

当你走了Y当然会变得越来越小,因为它从顶部长到底部。

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

您要注意铺设出像列表视图元素,这些将会给部分(或新的,你看不出来)的画布到您的视图绘制。这些意见将在为0x0的自己顶部/左侧位置。如果你需要绝对的,你必须继续调用 View.getLocationOnScreen(),并计算抵消自己。

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.

这篇关于了解如何实际的drawRect或图形中的Andr​​oid协调工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆