Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

positioning a compoundDrawable within TextView?

Tags:

android

I am setting a compound drawable to a TextView like so

txtView1.setCompoundDrawablesWithIntrinsicBounds(R.drawable.icon, 0, 0,0); 

The drawable is drawn to the left most position of the TextView. However I want to move it a little bit so that it doesn't sit on the left border of the TextView but it's like 10dip inside. I did some padding by using:

android:paddingLeft="10dip" 

But this pushes the text to move along with the compound drawable to the right by 10dip.

How do I move only the compound drawable by 10dip without affecting the text ?

like image 789
bytebiscuit Avatar asked Nov 23 '11 06:11

bytebiscuit


2 Answers

Its very simple. Just add the following piece code to your TextView

android:drawablePadding="10dip" 

This adds padding between your text and the image in the TextView.

like image 105
Antrromet Avatar answered Oct 07 '22 19:10

Antrromet


If you want to do it dynamically, you can use the method:

txtView1.setCompoundDrawablePadding (int pad); 
like image 33
DMunoz Avatar answered Oct 07 '22 17:10

DMunoz