下面是我的代码,我得到的图像x和y坐标与iPhone设备完全匹配
fragmentImageView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
float density = getActivity().getResources()
.getDisplayMetrics().density;
if (density == 4.0) {
displayMetrixDensity = 640;
}
if (density == 3.0) {
displayMetrixDensity = 480;
}
if (density == 2.0) {
displayMetrixDensity = 320;
}
if (density == 1.5) {
displayMetrixDensity = 160;
}
if (density == 1.0) {
displayMetrixDensity = 160;
}
rowSize.x = (int) event.getRawX();
rowSize.y = (int) event.getRawY();
int[] viewCoords = new int[2];
fragmentImageView.getLocationOnScreen(viewCoords);
rowSize.x = rowSize.x - viewCoords[0]; // viewCoords[0] is the X
// coordinate
rowSize.y = rowSize.y - viewCoords[1]; // viewCoords[1] is the y
// coordinate
// DisplayMetrics displayMetrics =
// getActivity().getResources().getDisplayMetrics();
int dp = Math
.round(rowSize.x
/ (displayMetrixDensity / DisplayMetrics.DENSITY_DEFAULT));
int d = Math
.round(rowSize.y
/ (displayMetrixDensity / DisplayMetrics.DENSITY_DEFAULT));
rowSize.x = dp;
rowSize.y = d;
}
});
这些像素也不支持Android上的大屏幕设备。
我怎么能解决它?