2013-04-30 169 views
0

我有一個clasical Android的問題,布提解決不了。ImageButton的高度和寬度

我有一個ImageButton的,但它變形,高度大於它應該是,這是代碼:

<?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="fill_parent" 
android:background="@drawable/background" 
> 
<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_weight="1" 
    android:gravity="center" 
    android:orientation="vertical" > 

     <!-- other content --> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" > 

     <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_gravity="bottom" /> 
     </LinearLayout> 

    </LinearLayout> 

這是我應該看到:

enter image description here

這是我所看到的:

enter image description here

我該如何解決這個問題?

回答

2

那是因爲你用你的圖片作爲背景 你應該把它作爲一個scource:

android:src="@drawable/banner_sabadell" 

,如果你會擁有一些問題大小,你會擁有和玩不同的屏幕與scale_type屬性

android:scaleType="fitXY" /// or some others 

,這將是更好地爲您從您的旗幟做出9patch圖像.. 葉氏,舒爾......你必須讓這樣的:

android:background="#00000000" 

android:background="@android:color/transparent" 
+0

我需要它作爲背景,因爲如果不是這樣,我看到的是一個圖像的按鈕,就它存在另一種方式來避免這種影響? – user1256477 2013-04-30 08:10:09

+0

在回答.. – Alex 2013-04-30 08:14:03

+0

9補丁。好主意 – 2013-04-30 08:14:24

1

嘗試使用scaleType = "fitCentre"。在設置高度寬度之前wrap_content

This link也可以幫助您識別要使用的刻度類型。