Android 如何在所有设备上获得相同图像的坐标?
我尝试了所有可能的解决方案,但它们对我不起作用。 我有一个带有图像的ImageView。我能够在触摸图像时获得坐标,但当我在不同分辨率的设备中单击图像的同一点时,坐标是不同的。 我希望所有设备上的坐标必须相同,这样我就能够得到图像被触摸的确切点 我目前的代码是:Android 如何在所有设备上获得相同图像的坐标?,android,android-layout,android-canvas,Android,Android Layout,Android Canvas,我尝试了所有可能的解决方案,但它们对我不起作用。 我有一个带有图像的ImageView。我能够在触摸图像时获得坐标,但当我在不同分辨率的设备中单击图像的同一点时,坐标是不同的。 我希望所有设备上的坐标必须相同,这样我就能够得到图像被触摸的确切点 我目前的代码是: @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVie
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView imageView=(ImageView)findViewById(R.id.imageView);
final TextView coordinateText=(TextView)findViewById(R.id.coordinateText);
imageView.setOnTouchListener(new View.OnTouchListener()
{
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
String text = " x = " + motionEvent.getX() + " and y = " + motionEvent.getY();
// Log.d("Tag", "X,Y : " + motionEvent.getX() + "," + motionEvent.getY());
coordinateText.setText(text);
return true;
}
});
}
activity_main.xml是:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="saleskit.orbitsys.com.damagemarkingdemo.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/coordinateText"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:src="@drawable/superb_dm_left_v01"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
使用ImageView
的倒置Matrix
,通过调用ImageView#getImageMatrix()
方法获取原始的Matrix
,谢谢你的回答。你能给我举个例子吗。我没有任何问题。有人能给我演示一下实现吗?到目前为止你尝试了什么?