How Do I Use 'RotateDrawable'?

后端 未结 7 2167
没有蜡笔的小新
没有蜡笔的小新 2020-12-15 19:34

Could anyone tell me how they have got \'RotateDrawable\' to work whether it be from code or XML or both? The documentation on animating Drawables is pretty poor and animati

7条回答
  •  余生分开走
    2020-12-15 20:11

    The following code returns a Drawable wrapper that rotates another Drawable programmatically:

    Drawable rotateDrawable(Drawable d, final float angle) {
        // Use LayerDrawable, because it's simpler than RotateDrawable.
        Drawable[] arD = {
            d
        };
        return new LayerDrawable(arD) {
            @Override
            public void draw(Canvas canvas) {
                canvas.save();
                canvas.rotate(angle);
                super.draw(canvas);
                canvas.restore();
            }
        };
    }
    

提交回复
热议问题