2011-11-22 13 views
8

tengo el siguiente botón:¿Cómo puedo escalar el fondo de un botón?

<Button 
android:id="@+id/buttonok" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:drawableLeft="@drawable/back_no_save" 
android:text="OK" /> 

Su aparición es:

enter image description here

¿Cómo se puede escalar que por mi estirable y mostrar una pequeña flecha?

Respuesta

1

Puede reducir el gráfico real al que apunta el dibujable.

+2

No es una buena idea. – breceivemail

+0

¿Qué le parece usar un ScaleDrawable? – zienkikk

5

yo no hink que pueda de XML. No hay ningún atributo xml que pueda hacer escala para botones. Puede hacerlo mediante programación, sin embargo, de la siguiente manera:

Bitmap originalBitmap= BitmapFactory.decodeResource(getResources(), R.drawable.icon); 
Bitmap scaledBitmap=Bitmap.createScaledBitmap(originalBitmap, newWidth, newHeight, true); 
txt.setBackgroundDrawable(new BitmapDrawable(bit)); 
1

Si no quiere tratar con Bitmap.createScaledBitmap entonces me parece que la mejor manera de hacerlo es crear su propio componente. Puede ampliar RelativeLayout y poner ImageView en él, por ejemplo.

0

Sé que esto es una entrada antigua, pero he hecho algo como esto:

<LinearLayout 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:padding="16dp" 
    android:id="@+id/XXXXXXXXXXXX" 
    android:orientation="horizontal"> 
    <ImageView 
     android:src="@drawable/XXXXXXXXXXXX" 
     android:layout_width="48dp" 
     android:layout_height="48dp" 
     android:scaleType="centerInside" 
     android:id="@+id/XXXXXXXXXXXXXXXX"/> 
    <TextView 
     android:id="@+id/XXXXXXXXXXXXXX" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:text="XXXXXXX" 
     android:layout_gravity="center"/> 
</LinearLayout> 
Cuestiones relacionadas