android怎么样来检查点是我的屏幕内 [英] android how to check if a Point is inside my screen
本文介绍了android怎么样来检查点是我的屏幕内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我得到一个Point对象把我的MapView Projectiion对象。
我有重叠的名单,我想检查,如果每个叠加是我目前的屏幕里(这是诅咒取决于缩放级别)。
我无法找到一个方法来检查,如果给定的点是在屏幕里面。
我所做的发现是,当我是从投影记录的点,这些点that're不在屏幕具有负值。
这是真的说,如果一个点有一个负值是我的屏幕外?
解决方案
的GeoPoint yourPoint = NULL; // W / E点ü希望看到出现在屏幕上 点newPoint = NULL; // X / Y点 MapView.getProjection()在toPixels(yourPoint,newPoint)。 //转换为XY点 INT高度= context.getResources()getDisplayMetrics()heightPixels。; INT宽度= context.getResources()getDisplayMetrics()widthPixels。; 矩形屏幕=新的矩形(0,0,宽,高); //矩形的重新presents屏幕 如果(screen.contains(newPoint.x,newPoint.y){
//你的一点是在屏幕上
}
i'm getting a Point object throw my MapView Projectiion object.
I have a list of Overlays and i want to check if each Overlay is inside my current screen (which is of curse depends on the zoom level).
I couldn't find a way to check if a given point is inside the screen.
What i did found out is that when i'm Logging the Points from the Projection, the points that're not in the screen have negative value..
is it true to say that if a Point has a negative value it is outside my screen ?
解决方案
GeoPoint yourPoint = null;// w/e point u wanna see is on the screen
Point newPoint = null; // x/y point
mapView.getProjection().toPixels(yourPoint, newPoint); //convert to xy Point
int height = context.getResources().getDisplayMetrics().heightPixels;
int width = context.getResources().getDisplayMetrics().widthPixels;
Rect screen = new Rect(0,0,width,height); //rect that represents your Screen
if(screen.contains(newPoint.x, newPoint.y){
// your point is on the screen
}
这篇关于android怎么样来检查点是我的屏幕内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文