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 ?

有帮助吗?

解决方案

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top