安卓:我如何获得一个图像/的ImageView内的XY坐标? [英] Android: How do I get the x y coordinates within an image / ImageView?

查看:1053
本文介绍了安卓:我如何获得一个图像/的ImageView内的XY坐标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的屏幕上的图像(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.

问候, 马蒂亚斯

推荐答案

您可以使用<一个href="http://developer.android.com/reference/android/view/View.html#getLocationOnScreen%28int%5B%5D%29"相对=nofollow> 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.

这篇关于安卓:我如何获得一个图像/的ImageView内的XY坐标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆