Is it possible to programmatically display a drawableLeft visualization

I add / remove drawableLeft programmatically:

((TextView)view).setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_icon, 0, 0, 0); ((TextView)view).setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); 

But since I use it on a list,

I need an option to remove drawableLeft for unselected lines without alignment problems.

What I want:

  AAA * BBB CCC 

What I get:

 AAA * BBB CCC 

I can get around this by adding a transparent icon,

but can I programmatically control this drawableLeft visibility?

+6
source share
1 answer

I'm not sure what type of view you use for drawing, but you can simply set the left padding to match the width of the drawn when it is not present.

 View.setPadding(left, 0, 0, 0); 
+1
source

Source: https://habr.com/ru/post/956075/


All Articles