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