Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Constrain drawableLeft and drawableRight's height to TextView's height

I have the following TextView:

<TextView
    android:drawableLeft="@drawable/loading"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Updating Rates" />

And the result is this:

How do I make the loading circle drawable constrain proportionally so its height matches the height of the text?

Also, if possible, I would like to add some spacing between the text and the image.

like image 488
Dzhuneyt Avatar asked Oct 07 '12 09:10

Dzhuneyt


2 Answers

To make the loading smaller just make the images smaller.

Or use RelativeLayout and put the loading in an ImageView and scale it.

Or you can add padding between the drawables and the text using android:drawablePadding (or setCompoundDrawablePadding()):

android:drawablePadding="3dp"
like image 77
JafarKhQ Avatar answered Nov 16 '22 03:11

JafarKhQ


I think I found the solution, but a bit late

Drawable drawable = getResources().getDrawable(R.drawable.s_vit);
drawable.setBounds(0, 0, (int)(drawable.getIntrinsicWidth()*0.5),(int)(drawable.getIntrinsicHeight()*0.5));
ScaleDrawable sd = new ScaleDrawable(drawable, 0, scaleWidth, scaleHeight);
Button btn = findViewbyId(R.id.yourbtnID);
btn.setCompoundDrawables(sd.getDrawable(), null, null, null); 
like image 8
Ravi Avatar answered Nov 16 '22 02:11

Ravi