安卓 :The unit of imageLayout. getHeight

标签 android image height width pixel

我正在 xml 文件中创建一个 imageLyout,使用这段代码这段代码:

    <com.manuelpeinado.imagelayout.ImageLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:custom="http://schemas.android.com/apk/res-auto"
    android:id="@+id/image_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#aaa"
    custom:fit="both"
    custom:image="@drawable/plan"
    custom:imageHeight="1744"
    custom:imageWidth="1150" >
 </com.manuelpeinado.imagelayout.ImageLayout>

当我在 drawbale-hdpi 属性中输入图像时,我看到图像尺寸为:515 * 348 像素。

当我使用这段 java 代码时:

                     hauteurLayout = imageLayout.getHeight();
             largeurLayout = imageLayout.getWidth() ;

我得到这个结果:407 * 601。

好吧,我对所有这些维度感到困惑,为什么它们不同并且代表相同的图像?

我需要在 map 上画一些东西,所以我需要知道我必须使用的正确尺寸,以便在准确的位置绘制对象。

这是图片(我使用的是 horizo​​ntalScreeView ):

enter image description here

最佳答案

要支持多种屏幕分辨率,您应该使用与密度无关的像素 (dip),也称为 dp。
这是一种从 px(取决于屏幕分辨率)缩放到 dp(在每个设备上都能很好地缩放)的缩放方法:

private final int px2dp(int px)
{
    final float scale = getResources().getSystem().getDisplayMetrics().density;
    return (int) (px * scale);
}

关于安卓 :The unit of imageLayout. getHeight,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23822802/

相关文章:

android - 在android中的EditText上键入时如何过滤ListView数据

Jquery SlideUp 高度

jquery - 水平 div 上的自动页面高度

python - 获取图像模式 PIL Python

jquery - 隐藏任何包含图像的第一个元素

c++ - 直方图均衡化实现

javascript - 均衡 div 的高度

android - 可穿戴设备未安装应用程序(Android Wear 功能标准)

java - Android:包含标题和副标题的列表项的默认布局

android - HTC one - 应用程序每次都被杀死