Gea*_*óid 7 android translation coordinates android-sensors
我有一个包含在相对布局中的图像视图.我试图获取图像视图顶部的屏幕y坐标和图像视图底部的屏幕y坐标.我试过这个:
float yMin = (float)levelH.getTop();
float yMax = (float)levelH.getBottom();
Run Code Online (Sandbox Code Playgroud)
漂浮yMin似乎几乎是正确的.我正在这个图像视图(IM1)上下翻译另一个图像视图(IM2).所以我试图设置一个限制(IM2)可以向上和向下翻译.所以我的想法是得到(IM1)的y顶部和底部我可以将它们设置为max和min.
有人知道怎么做吗?
ps我用android accelometer来移动(IM2)
Ivo*_*ers 17
getTop()ansd getBottom()看看它的父母内部的坐标.要获得它在屏幕上的位置坐标,您可以使用getLocationOnScreen
像这样使用它:
int[] coords = {0,0};
view.getLocationOnScreen(coords);
int absoluteTop = coords[1];
int absoluteBottom = coords[1] + view.getHeight();
Run Code Online (Sandbox Code Playgroud)