2013-03-19 3 views
1

배너가있는 레이아웃이 있습니다. 나머지 코드는 모두 삭제했습니다.배너 고정 너비

이미지 버튼으로 만듭니다.

레이아웃은 레이아웃 등의 화상을 갖는 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

하여 ImageButton 폭을 일치하도록 버튼을 강요하고,이

<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> 

을 시도합니다. 이미지를 src로 설정했기 때문에 이미지의 크기가 조정되지 않습니다.이 목적으로 이미지를 으로 설정하고 android:src으로 설정하면됩니다.

0

에 대해 android:layout_width에서 match_parent으로 설정하십시오. 당신이하여 ImageButton에 대한 wrap_content를 사용하는 것처럼

+0

동일한 결과가 나타납니다. – user1256477