Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to scale drawableleft & drawableright in textview?

I have TextView with drawableLeft & drawableRight in List item. The problem is, whenever the height of TextView is larger, drawableLeft & drawableLeft didn't automatically scale based on the height of the TextView.

Is it possible to scale the height of drawableLeft & drawableRight in TextView ? (I was using 9 patch image)

textview drawableleft & drawableright's height problem

like image 714
hakim Avatar asked Mar 30 '11 08:03

hakim


People also ask

How do I change drawable size on android?

Once you import svg file into Android Studio project, you are going to see <vector> resource then just change the size as you want by width , height attributes. viewportWidth and viewportHeight is to set size for drawing on virtual canvas.

How can set image in center of button in Android?

Create a RelativeLayout "wrap_content" with the button image as the background or the button itself as the first element of the layout. Get a LinearLayout and set it to "layout_centerInParent" and "wrap_content". Then set your Drawable as an Imageview.


1 Answers

This might help you out. There are two properties scaleX and scaleY

The code below will scale down the image and the text with 30%. Therefore you have to increase the font size with that many "sp", so that when it get re-sized (scaled) it would fit the "sp" you prefer.

Example. If I set the font to 18, then 30% out of 18 is 5.4sp, so roughly, this is the value I am targeting at, because when it gets scaled, it would become 13sp

<TextView         android:textSize="18sp"         android:scaleX="0.7"         android:scaleY="0.7" 

The last thing to do is set the CompundDrawable.

tview.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(R.drawable.xxx), null, null, null); 
like image 102
kirilv Avatar answered Sep 18 '22 19:09

kirilv