2009-04-28 28 views
4
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <ImageView    
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:src="@drawable/wallpaper" /> 
</RelativeLayout> 

大小@drawable/peetscoffee_wallpaper是640x480,但它不是水平居中。 我該如何解決這個問題?ImageView麻煩

回答

9

嘗試android:gravity="center"android:layout_gravity="center"而不是centerHorizontal="true"

然而,我懷疑這會理智的行爲與大小設置爲wrap_content的圖像 - 你可能希望定義一些圖像縮放方法與android:scaleType(如fitCenter)並將其設置爲fill_parent而非wrap_content640x480比當前真實世界的Android設備支持的320x480大。或者只是縮小你正在使用的圖像,以便設備不必做這項工作。