2013-03-19 103 views
1

我有一個橫幅佈局。我刪除了其餘的代碼。橫幅固定寬度

我將它創建爲imagebutton。

佈局具有圖像作爲佈局,例如在HDPI,尺寸爲:720x1200像素,並且ImageButton的是720x200

這是的ImageButton:

enter image description here

但imagebutton沒有固定寬度,但我沒有找到錯誤!

enter image description here

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:gravity="center" 
android:background="@drawable/background" 
> 

    <ImageButton 
      android:id="@+id/sabadell_but" 
      android:background="@null" 
      android:contentDescription="@string/infoDesc" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="10dip" 
      android:src="@drawable/banner_sabadell" /> 

    </LinearLayout> 

我怎樣才能得到固定寬度的ImageButton?

回答

1

試試這個

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:gravity="center" 
android:background="@drawable/background"> 

<ImageButton 
     android:id="@+id/sabadell_but" 
     android:background="@drawable/banner_sabadell" 
     android:contentDescription="@string/infoDesc" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="10dip" 
     /> 

</LinearLayout> 

正如你已經使用wrap_content的ImageButton的,它迫使你的按鈕匹配的ImageButton寬度。由於您已將圖像設置爲src,因此不會縮放圖像。爲此,您可以將圖像設置爲android:background,而不是將圖像設置爲android:src

0

android:layout_width設置爲match_parent爲您的ImageButton

+0

我得到了同樣的結果 – user1256477 2013-03-19 08:46:29