Pregunta

I'm working on optimization for my app and I'm trying to replace relatice layout with text and image with only TextView that contains compound drawable. Existing implementation of side menyou has a single image with level for each position. It's much easier to set the same res to compound drawable but is it possible to change level in adapter code ?

¿Fue útil?

Solución

to do it via code:

(let's say "text" is your TextView

and "level" is an int with your desired level)

        Drawable[] drawables = text.getCompoundDrawables();
        for (Drawable drawable : drawables) {
            if (drawable != null)
                drawable.setLevel(level);
        }

use this if you are using start/end instead of left/right:

      text.getCompoundDrawablesRelative()

this will change the levels of all the drawables, if you just want one of the don't use the for loop

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top