Bob
Bob

Reputation: 23000

How can I scale the background of a button?

I have the following button:

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

Its appearence is:

enter image description here

How can I scale down my drawable and show a small arrow?

Upvotes: 8

Views: 15389

Answers (5)

Shane Sepac
Shane Sepac

Reputation: 826

I know this is an old post, but I did something like this:

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

Upvotes: 0

a.ch.
a.ch.

Reputation: 8380

If you don't want to deal with Bitmap.createScaledBitmap then it seems to me that the best way to do it is to create your own component. You can extend RelativeLayout and put ImageView into it, for example.

Upvotes: 1

rDroid
rDroid

Reputation: 4945

I don't hink you can from xml. There's no xml attribute that can do scaling for buttons. You can do it programatically though, in the following way :

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

Upvotes: 4

Pathos
Pathos

Reputation: 399

You could use an ImageButton and try android:scaleType

ImageView.ScaleType

Upvotes: 9

zienkikk
zienkikk

Reputation: 2414

You could scale down the actual graphic that the drawable points to.

Upvotes: 1

Related Questions