Android 获取Imageview不同区域的特定像素参数?

Android 获取Imageview不同区域的特定像素参数?,android,imageview,clickable,Android,Imageview,Clickable,我有一个飞机内部的蓝图,它会显示每个座位和区域的相关信息,作为点击祝酒词。按钮附加到图像本身,因为我希望布局可以缩放和平移,这是我在 但是,由于我们定义可点击区域的方法是以以下格式硬编码的(如上面更详细的链接所示): 这种方法要求我知道精确的x、y坐标以及可点击区域的宽度和高度,这对我来说是一个很大的挑战,因为我的应用程序需要的一个重要方面是可点击性的准确性,因为图像视图中有大量可点击区域 因此,我的问题是,是否有一种方法可以通过layout.xml选项卡或其他任何地方来绘制区域并提取其相应的

我有一个飞机内部的蓝图,它会显示每个座位和区域的相关信息,作为点击祝酒词。按钮附加到图像本身,因为我希望布局可以缩放和平移,这是我在

但是,由于我们定义可点击区域的方法是以以下格式硬编码的(如上面更详细的链接所示):

这种方法要求我知道精确的x、y坐标以及可点击区域的宽度和高度,这对我来说是一个很大的挑战,因为我的应用程序需要的一个重要方面是可点击性的准确性,因为图像视图中有大量可点击区域

因此,我的问题是,是否有一种方法可以通过layout.xml选项卡或其他任何地方来绘制区域并提取其相应的x、y坐标以及每个可单击区域的宽度和高度

非常感谢您的帮助

编辑: 在建议的帮助下,在将DrawView代码附加到线性布局后,我能够裁剪以查找坐标。 但是,在可单击区域图像中使用坐标时,裁剪区域的坐标与可单击区域不对应。我已经确保将线性布局和imageview的宽度和高度都设置为“fill_parent”,所以我不确定出了什么问题。以下是我的项目中的一些附加代码,我认为这些代码可能与此相关:

在DrawView下(将以下零件添加到):

activity.xml:

<ImageView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/imageView3"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true"
    android:src="@drawable/b777_212b_1" />

<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:id="@+id/myLinearLayout"
    android:layout_alignRight="@+id/imageView3"
    android:layout_alignEnd="@+id/imageView3"></LinearLayout>

基本上,在你的问题中,你需要一个可以在你的图像中移动的相机,这样你就可以根据你的需要调整矩形,这与android图像裁剪中使用的技术完全相同。唯一的区别是,你不会裁剪图像,而是从相机视图中获取点

有关详细信息,请参见此问题

基本上,在您的问题中,您需要一个可在图像中移动的相机,以便您可以根据自己的需要调整矩形,这与android图像裁剪中使用的技术完全相同。唯一的区别是,您不会裁剪图像,而是从相机视图中获取该点

有关详细信息,请参见此问题

请参见
ImageView#getImageMatrix
:“返回视图的可选矩阵。这在绘制视图时应用于视图的可绘制矩阵。”请参见
ImageView#getImageMatrix
:“返回视图的可选矩阵。这在绘制视图时应用于视图的可绘制矩阵。”谢谢,这正是我所需要的。但是,裁剪后的坐标与ClickableAreasImages中使用的坐标不一致,即使我尝试对齐线性布局和imageview。我已经编辑了我的帖子以获得更深入的信息。不知道怎么了,谢谢,这就是我要的。但是,裁剪后的坐标与ClickableAreasImages中使用的坐标不一致,即使我尝试对齐线性布局和imageview。我已经编辑了我的帖子以获得更深入的信息。不知道怎么了。
 case MotionEvent.ACTION_UP:
                while (isNotPrinted) {

                    int x = colorballs.get(0).getX();
                    int y = colorballs.get(0).getY();
                    int width = colorballs.get(2).getX() - colorballs.get(0).getX();
                    int height = colorballs.get(1).getY() - colorballs.get(0).getY();
                    Log.i("x, y, width, height:",Integer.toString(x) + ", " + Integer.toString(y) +
                            ", "+ Integer.toString(width) + ", "+Integer.toString(height) );
                    isNotPrinted = false;
                }

                break;
<ImageView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/imageView3"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true"
    android:src="@drawable/b777_212b_1" />

<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:id="@+id/myLinearLayout"
    android:layout_alignRight="@+id/imageView3"
    android:layout_alignEnd="@+id/imageView3"></LinearLayout>
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_coordinates_tester);


        LinearLayout layout = (LinearLayout) findViewById(R.id.myLinearLayout);
        DrawView myView = new DrawView(this);
        myView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
        // myView.setText("Added myView");
        layout.addView(myView);

        // Add image
        ImageView image = (ImageView) findViewById(R.id.imageView3);
        image.setImageResource(R.drawable.b777_212b_1);

    }