3 回答

TA貢獻1775條經(jīng)驗 獲得超11個贊
這至少對我來說適用于API 10+:
final float[] getPointerCoords(ImageView view, MotionEvent e)
{
final int index = e.getActionIndex();
final float[] coords = new float[] { e.getX(index), e.getY(index) };
Matrix matrix = new Matrix();
view.getImageMatrix().invert(matrix);
matrix.postTranslate(view.getScrollX(), view.getScrollY());
matrix.mapPoints(coords);
return coords;
}

TA貢獻1828條經(jīng)驗 獲得超4個贊
除了考慮由于填充而產(chǎn)生的偏移量(邊距是布局的一部分,它是視圖外部的空間,不必考慮),如果縮放圖像,則可以獲取圖像矩陣(ImageView.getImageMatrix())來縮放坐標。
編輯:您可以獲取x / y比例因子和轉(zhuǎn)換量,獲取值數(shù)組并使用相應(yīng)的索引常量:
float[] values;
matrix.getValues(values);
float xScale = values[Matrix.MSCALE_X];
請注意,翻譯不包括填充,您仍然需要單獨考慮。當(dāng)有一些“空白”空間時,例如在FIT_CENTER縮放中使用轉(zhuǎn)換。
- 3 回答
- 0 關(guān)注
- 431 瀏覽
添加回答
舉報