1
如何独立检测触摸坐标显示大小?在不同的设备上检测相同的触摸事件点。在不同密度的Android设备上检测触摸事件
如何独立检测触摸坐标显示大小?在不同的设备上检测相同的触摸事件点。在不同密度的Android设备上检测触摸事件
触摸事件将始终返回像素的x,y坐标。如果你想要百分比,你必须以编程方式进行。您需要获取设备的屏幕大小,然后相应地分割以获得百分比。
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int height = displaymetrics.heightPixels;
int width = displaymetrics.widthPixels;
让他们以百分比
int percentageX= (int)((x*100)/width)
int percentageY= (int)((y*100)/height)