2013-12-12 12 views
36

In einer App, an der ich arbeite, habe ich mehrere ImageButtons. Jeder ImageButton hat einen Hintergrund und einen Inhalt in Form eines Zeichens. Im Moment ist das Zeichen innerhalb der Grenzen des ImageButtons maximal groß, aber ich möchte, dass es verkleinert wird, also muss ich etwas Padding hinzufügen. Die Sache ist, dass wenn ich das versuche, es keine Wirkung hat. Mein XML ist wie folgt für jedes ImageButton:Padding funktioniert nicht auf 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" /> 

Irgendwelche Ideen, warum die Polsterung nichts tut?

Vollständiger XML-Code:

<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

Können Sie bitte alle Ihre XML-Code hinzu? – user2235615

+0

@ user2235615 Ich habe die Frage aktualisiert :) – Zero

Antwort

86

Sie müssen Ihre Image Definition

android:scaleType="fitCenter" 

oder andere Scaletype wie fitXY, hinzuzufügen, da standardmäßig Bild versuchen, so zu skalieren viel wie möglich und Padding ignorieren

+1

Besser ist ScaleX = 1,4 und ScaleX = 1,4 –

1

Das Auffüllen wirkt sich nur auf das Attribut android:src aus, nicht auf die android:background.

die erste auf Ihre Schaltfläche Bild einstellen und diese auf android:background="@android:color/transparent"