2013-12-12 5 views
36

현재 진행중인 앱에서 ImageButton이 여러 개 있습니다. 각 ImageButton에는 드로어 블 형식의 배경과 내용이 있습니다. 현재 드로어 블은 ImageButton의 범위 내에서 최대 크기이지만 크기를 축소하여 약간의 패딩을 추가해야합니다. 문제는 내가 그렇게하려고 할 때 아무런 효과가 없다는 것입니다. 내 XML은 각 ImageButton에 대해 다음과 같습니다.ImageButton에서 안쪽 여백이 작동하지 않습니다.

<ImageButton 
    android:id="@+id/button_zero" 
    android:layout_width="0dip" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:padding="10dip" 
    android:src="@drawable/button_zero" 
    android:background="@drawable/button_background" /> 

패딩이 아무런 효과가없는 이유는 무엇입니까?

전체 XML 코드 :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#222222" 
    tools:context=".Main" > 

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

     <!-- Row One --> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" > 
      <ImageButton 
       android:id="@+id/button_zero" 
       android:layout_width="0dip" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:padding="10dip" 
       android:src="@drawable/button_zero" 
       android:background="@drawable/button_front" /> 
      <ImageButton 
       android:id="@+id/button_one" 
       android:layout_width="0dip" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:padding="10dip" 
       android:src="@drawable/button_one" 
       android:background="@drawable/button_front" /> 
      <ImageButton 
       android:id="@+id/button_two" 
       android:layout_width="0dip" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:padding="10dip" 
       android:src="@drawable/button_two" 
       android:background="@drawable/button_front" /> 
      <ImageButton 
       android:id="@+id/button_three" 
       android:layout_width="0dip" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:padding="10dip" 
       android:src="@drawable/button_three" 
       android:background="@drawable/button_front" /> 
      <ImageButton 
       android:id="@+id/button_four" 
       android:layout_width="0dip" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:padding="10dip" 
       android:src="@drawable/button_four" 
       android:background="@drawable/button_front" /> 
     </LinearLayout> 

     ... same for other rows 

    </LinearLayout> 

+0

로 버튼 이미지에 대한 제 후자를 설정? – user2235615

+0

@ user2235615 질문 : – Zero

답변

86

당신은 기본 이미지로로 확장하려고하기 때문에, 당신하여 ImageButton 정의

android:scaleType="fitCenter" 

또는 fitXY 같은 다른 scaleType에 추가해야 가능하면 많이하고 패딩은 무시하십시오.

+1

더 나은 ScaleX = 1,4 및 ScaleX = 1,4 –

1

패딩은 android:src 속성에만 적용되며 android:background에는 적용되지 않습니다.

사용하면 XML의 모든 코드를 추가하십시오 수 android:background="@android:color/transparent"

관련 문제