Is it possible to rotate a drawable in the xml description?

后端 未结 4 697
天涯浪人
天涯浪人 2020-12-08 00:12

I am creating an app, with resources that can be reused (because buttons are always the same, but mirrored or rotated). I do want to use the same resource so I don\'t have t

4条回答
  •  执念已碎
    2020-12-08 00:23

    I could rotate in XML:

    
    
    
    

    The fromDegrees is important.

    Basically this is a rotate animation defined in XML. With fromDegrees you define the initial rotated state. The toDegrees is the final rotated state of the drawable in the animation sequence but can be anything if you don't want to use animation.

    I don't think it allocates resources for animation as it doesn't have to be loaded as animation. As a drawable it is rendered as it's initial state and should be put in the drawable resource folder. To use it as an animation you should put it in anim resource folder and can start the animation like this (just an example):

    Animation rotation = AnimationUtils.loadAnimation(this, R.anim.rotation);
    rotation.setRepeatCount(Animation.INFINITE);
    myView.startAnimation(rotation);
    

提交回复
热议问题