为什么在ImageView的错绘制的宽/高? [英] Why are the Width / Height of the drawable in ImageView wrong?

查看:119
本文介绍了为什么在ImageView的错绘制的宽/高?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

应该是很简单的。

当我拉 image.getDrawable()。getIntrinsicWidth()我得到一个比源图像宽度。它的X坐标将返回,而不是1920 2880这是1.5倍太大了?

我不知道羯羊为中心的scaleType ImageView的影响,但根据的文档

  

中心在观看图片,但是不执行任何缩放。

下面是源:

 < ImageView的
    机器人:ID =@ + ID /和backgroundImage
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:SRC =@可绘制/背景
    机器人:scaleType =中心/>
 

解决方案

您说的绘制是从你的 / RES 文件夹。哪个文件夹是哪个?

  • / RES /绘制
  • / RES /绘制-MDPI
  • / RES /绘制,华电国际

什么是你正在测试的设备的密度?它是一台Nexus S采用了240dpi一般密度?因为如果你的源绘制位于绘制-MDPI 文件夹,您正在测试一个240dpi设备上,那么Android系统将自动的比例缩放绘制了 1.5 这样的物理尺寸将与在160dpi的基线设备的密度一致。

当你调用 getIntrinsicWidth()返回什么是绘制的希望是Android的缩放绘制后的尺寸。你会发现, 2880 = 1920×1.5

如果您放置在绘制 / RES /绘制 Android系统会将那些可绘制作为意味着MDPI设备,从而在你的Nexus S的倍增如果这是为了对华电国际的屏幕,你不希望这种高档然后尝试将其放置在绘制 - 华电国际

Should be a simple one.

When I pull image.getDrawable().getIntrinsicWidth() I get a value larger than the source image width. It's X coordinate is returning 2880 instead of 1920 which is 1.5 times too big?

I wondered wether the ImageView having a scaleType of "center" effected it but, according to the documentation:

"Center the image in the view, but perform no scaling."

Here is the source:

<ImageView  
    android:id="@+id/backgroundImage"   
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:src="@drawable/background"
    android:scaleType="center"/>

解决方案

You said the drawable is from your /res folder. Which folder is it in?

  • /res/drawable
  • /res/drawable-mdpi
  • /res/drawable-hdpi

    etc..

And what is the density of the device you are testing on? Is it a Nexus S with general density of 240dpi? Because if your source drawable is located in the drawable-mdpi folder and you are testing on a 240dpi device, then the Android system will automatically scale the drawable up by a factor of 1.5 so that the physical size will be consistent with the baseline device density at 160dpi.

When you call getIntrinsicWidth() what is returned is the size the drawable wants to be after Android scales the drawable. You'll notice that 2880 = 1920 * 1.5

If you placed the drawable in /res/drawable the Android system treats those drawables as meant for mdpi devices, thus the upscaling in your Nexus S. If this was meant for hdpi screens and you do not want this to upscale then try placing it in drawable-hdpi

这篇关于为什么在ImageView的错绘制的宽/高?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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