Android scaledrawable doesn't seems to work

前端 未结 5 1212
旧时难觅i
旧时难觅i 2020-12-09 01:58

I\'m trying out the android ScaleDrawable

But it doesn\'t seem to work... I created the xml as in the documentation example and I have a logo.png in the drawable fol

5条回答
  •  囚心锁ツ
    2020-12-09 02:31

    To answer to the initial question, you just have to initialize your ScaleDrawable's Level with 10 000 in your onCreate. You get your ImageView, ImageButton's drawable using getIcon or getBackground (depends if you set it as a source or a background) and then call setLevel on it. For a MenuItem, the code looks like :

        editMenuItem = menu.findItem(R.id.action_edit);
        menuItemEdit_ScaleDrawable = (ScaleDrawable) editMenuItem.getIcon();
        //when playing with scaleDrawable always initialize the level
        menuItemEdit_ScaleDrawable.setLevel(10000);
    

    I use ScaleDrawable when running animation that changes the size of the drawable. For your usecase, I definitely prefer managing the size of the component not the drawable displayed by the component.

提交回复
热议问题