positioning a compoundDrawable within TextView?
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:
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 ?
3 Solutions collect form web for “positioning a compoundDrawable within TextView?”
Its very simple. Just add the following piece code to your TextView
This adds padding between your text and the image in the TextView.
If you want to do it dynamically, you can use the method:
txtView1.setCompoundDrawablePadding (int pad);
Quick fix –
txtView1.setText(" "+<your text>);
You can put 1/2 spaces.. or best is to extend textview and modify it the way you want. 🙂