我是android的初学者,我正在寻找放大页面中的视图的xy位置,但我尝试了很多我无法得到它。我使用下面的编码,但我在前后获得相同的位置放大。请任何人发布缩放后查找xy位置的代码。
private int fieldImgXY[] = new int[2];
v.getLocationOnScreen(fieldImgXY);
Log.v("Log",fieldImgXY[0]+" "+fieldImgXY[1]);
我的完整代码:
zoom = (ZoomView) findViewById(R.id.maincontainerScroller);
imageView = new ImageView(this);
imageView.setImageResource(R.drawable.ic_launcher);
imageView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
zoom.addView(imageView);
imageView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
v.getLocationOnScreen(fieldImgXY);
Log.v("Log",fieldImgXY[0]+" "+fieldImgXY[1]);
}
});
答案 0 :(得分:0)
从图像中获取绝对坐标我使用此方法:
void calculeAbsoluteCoorde(MotionEvent e){
float []m = new float[9];
matrix.getValues(m);
float transX = m[Matrix.MTRANS_X] * -1;
float transY = m[Matrix.MTRANS_Y] * -1;
float scaleX = m[Matrix.MSCALE_X];
float scaleY = m[Matrix.MSCALE_Y];
lastTouchX = (int) ((e.getX() + transX) / scaleX);
lastTouchY = (int) ((e.getY() + transY) / scaleY);
lastTouchX = Math.abs(lastTouchX);
lastTouchY = Math.abs(lastTouchY);
}
我习惯使用矩阵进行缩放,我希望它可以帮助你