问题
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:
How can I scale down my drawable and show a small arrow?
回答1:
You could use an ImageButton and try android:scaleType
ImageView.ScaleType
回答2:
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));
回答3:
You could scale down the actual graphic that the drawable points to.
回答4:
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.
回答5:
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>
来源:https://stackoverflow.com/questions/8223936/how-can-i-scale-the-background-of-a-button