如何获得android中所有分辨率的图像相同的坐标? [英] How to get same co-ordinates for image for all resolutions in android?

查看:161
本文介绍了如何获得android中所有分辨率的图像相同的坐标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我坚持让x& y所有分辨率的图像的坐标。

I stucked with getting x & y co-ordinates of an image for all resolutions.


  1. 320,适用于屏幕配置如下的设备:

    • 240x320 ldpi(QVGA手机)

    • 320x480 mdpi(手机)

    • 480x800 hdpi(高密度手机)

我创建了我的图像视图与原始大小的图像像1500 x 1119.当我触摸图像时,我可以通过onTouch()使用坐标。如果在所有设备中更改了坐标,我的问题。我变得与众不同x& y值在不同的欺骗中。我不能得到相同的x& y所有分辨率的值。我该如何解决这个问题?

I have created my image view with original size of an image like 1500 x 1119. When i touched the image i can get the co-ordinates using by onTouch(). My issue if the co-ordinates are changed in all device. I am getting different x & y values in different deceives . I can't get same x & y values for all the resolutions. How can i resolve this?

推荐答案

请设置显示密度

    float density = getActivity().getResources().getDisplayMetrics().density;
    if (density == 4.0) {
        displayMetrixDensity = 640;
    }
    if (density == 3.0) {
        displayMetrixDensity = 480;
    }
    if (density == 2.0) {
        displayMetrixDensity = 320;
    }
    if (density == 1.5) {
        displayMetrixDensity = 160;
    }
    if (density == 1.0) {
        displayMetrixDensity = 160;
    }

这篇关于如何获得android中所有分辨率的图像相同的坐标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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