安卓:我如何获得一个图像/的ImageView内的XY坐标?坐标、如何获得、图像、ImageView

由网友([考试作弊天经地义])分享简介:我有我的屏幕上的图像(ImageView的)。图像占据了大约一半的屏幕的,这意味着可以点击两者上的图像和关于图像的边I have an image (ImageView) on my screen. The image takes up roughly half of the screen which means t...

我有我的屏幕上的图像(ImageView的)。图像占据了大约一半的屏幕的,这意味着可以点击两者上的图像和关于图像的边

I have an image (ImageView) on my screen. The image takes up roughly half of the screen which means that you can click both on the image and on the side of the image.

如何,我得到的X - 和Y坐标在屏幕上,当我点击的形象?

How to I get the x -and y coordinates on the screen when I click on the image?

我试图用的onTouchEvent,但只有当我点击了图像的外部调用,而不是当我点击图片。

I tried using onTouchEvent but it is only called when I click outside of the image, not when I click on the image.

问候, 马蒂亚斯

推荐答案

您可以使用 getLocationOnScreen将()

You can use getLocationOnScreen()

imageView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            int[] values = new int[2]; 
            view.getLocationOnScreen(values);
            Log.d("X & Y",values[0]+" "+values[1]);
        }
    });

此外, 这个答案 我的将是有用的。

Also, this answer of mine will be useful as well.

阅读全文

相关推荐

最新文章