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 ?
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.
If you want to do it dynamically, you can use the method:
txtView1.setCompoundDrawablePadding (int pad);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With