2013-04-30 172 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也可以帮助您识别要使用的刻度类型。