android屏幕坐标如何工作? [英] How do android screen coordinates work?
问题描述
我正在使用 Android Animation
并且我发现 Android 坐标系非常混乱,所以我在这里询问有关坐标如何在 Android 中工作的问题.我正在关注此图像以将一个视图移动到另一个视图,但它似乎不起作用:
I am working with Android Animation
and I have found the Android coordinate system to be quite confusing so I am here to ask this question about how coordinates work in Android. I am following this image for moving one view to another but it seems it's not working:
推荐答案
这张图片展示了两个方向(横向/纵向)
要获得 MaxX 和 MaxY,请继续阅读.
To get MaxX and MaxY, read on.
对于 Android 设备屏幕坐标,以下概念适用.
For Android device screen coordinates, below concept will work.
Display mdisp = getWindowManager().getDefaultDisplay();
Point mdispSize = new Point();
mdisp.getSize(mdispSize);
int maxX = mdispSize.x;
int maxY = mdispSize.y;
- ** **对于支持 android api 级别早于 13 的设备.可以使用以下代码.
Display mdisp = getWindowManager().getDefaultDisplay();
int maxX= mdisp.getWidth();
int maxY= mdisp.getHeight();
(x,y) :-
1) (0,0) 是左上角.
2) (maxX,0) 是右上角
3) (0,maxY) 是左下角
4) (maxX,maxY) 是右下角
这里的 maxX 和 maxY 是以像素为单位的屏幕最大高度和宽度,我们在上面给定的代码中检索到.
here maxX and maxY are screen maximum height and width in pixels, which we have retrieved in above given code.
这篇关于android屏幕坐标如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!