2

如何在Android中顯示具有以下配置的圖像?如何在Android中顯示此圖片?

  • 保留原始縱橫比(圖像可以被縮放,但是未延伸)
  • 填充父
  • 的寬度對齊到母體

下面的底部不工作:

<ImageView 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:scaleType="fitCenter" 
android:layout_alignParentBottom="true" 
android:src="@drawable/background" /> 

使用上述xml的ImageView獲取父的寬度,但圖像插件IDE的ImageView不。

+1

如果你也可以告訴我們什麼不起作用會有幫助嗎? – 2010-11-15 11:21:52

+0

@Octavian完成。 – hpique 2010-11-15 11:25:30

回答

0

有些觀點。 如果你想manteint寬高比,而不是fitCenter的你應該嘗試centerInside

Scale the image uniformly (maintain the image's aspect ratio) so 
that both dimensions (width and height) of the image will be equal 
to or less than the corresponding dimension of the view (minus padding). 

請記住,使用您的應用程序的設備可能有不同的屏幕尺寸。 如果你的背景圖像是可以延伸的東西,我會建議你嘗試一下NinePatchDrawable

+0

謝謝Macarse。背景可以縮放,但不能拉伸。 – hpique 2010-11-15 11:41:12

+3

另外,不應該fitCenter也保持寬高比?抱歉。我發現ScaleType的文檔有點混亂。 – hpique 2010-11-15 11:54:15

相關問題