2012-03-02 112 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> 
相關問題