2012-03-02 113 views
1

我有这样的代码:什么原因导致此PNG呈现不良?

<RelativeLayout 
      android:orientation="vertical" 
      android:layout_height="match_parent" 
      android:layout_width="398px" 
      android:layout_marginTop="35px" 
      android:layout_alignParentRight="true" > 
      .... 
<ImageView 
       android:layout_width="373px" 
       android:layout_height="222px" 
       android:layout_marginTop="35px" 
       android:src="@drawable/hairfall_text" 
       android:layout_below="@+id/pr_title" /> 
</RelativeLayout> 

它使得这个图像显示这样的我的设备 上(P7500银河标签10.1要准确):

enter image description here

这是实际可绘制,因为它在我的资源文件夹中:

enter image description here

已经GOOGLE和相关的信息已经被使用,我已经调整了图像的像素格式为ARGB_8888(32位),同时设置活动的窗口pixelformat(getWindow().setFormat(PixelFormat.RGBA_8888);)什么都不做。

我希望有人能够对此事阐明一些看法。非常感谢。

+0

更新:我使用的解决方案是在资源增加没有dpi的文件夹,Android不缩放或调整摆在那里不过请注意,任何资源这是高度产生没有足够的内存错误 – lock 2012-04-23 01:22:40

回答

1
  1. 首先,如果你能做到比做“WRAP_CONTENT”的高度和宽度例如 layout_height =您ImageView.And “WRAP_CONTENT”layout_width = “WRAP_CONTENT”,你也可以做相同的,但FILL_PARENT你父RelativeLayout的。
  2. 其次使用“dp”代替“px”。建议使用。

LINK for android measurement。 试试这个,如果它会起作用。

+0

即时通讯完全意识到不使用px的规则,尽管在这种情况下根据客户端的要求打破它,顺便说一句,这里上传的图像不是实际图像(它被剪切到隐藏公司信息),并且我刚刚注意到我也截取了截图的图片。但是你明白了,即使在明确地告诉它将图像显示在373 * 222像素盒子中的时候,android render也会这样显示。 – lock 2012-03-02 06:17:42

+0

哦,等等,wrap_content做了这项工作,图像不再乱码,但它似乎太小虽然如此谢谢。然而,我想知道android是如何解释layout_height =“222px”或layout_width =“373px”? 它会将它转换为DP吗? – lock 2012-03-02 06:22:20

+0

@lock干杯!为您的问题solution.I编辑我的答案与链接。请检查它希望它会帮助你.. – 2012-03-02 06:25:37

0

不固定的高度和宽度与价值观

<RelativeLayout 
     android:orientation="vertical" 
     android:layout_height="fill_parent" 
     android:layout_width="fill_parent" 
     android:layout_marginTop="35dp" 
     android:layout_alignParentRight="true" > 
     .... 
<ImageView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_marginTop="35px" 
      android:src="@drawable/hairfall_text" 
      android:layout_below="@+id/pr_title" /> 
</RelativeLayout> 
相关问题