有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Android查看旋转动画并设置旋转未按预期工作

我试图将视图旋转90度,但每次调用此方法时,视图会向前跳90度,然后再旋转90度

我试着玩数字游戏,但没有成功。这段代码的工作原理似乎有些我不明白的地方

有人能解释一下目前正在发生的事情,以及为了达到预期的效果需要做哪些改变吗

public void RotatePoint(float toDegrees) {
    final RotateAnimation rotate =
        new RotateAnimation(pt.getRotation(), pt.getRotation() + toDegrees,
            RotateAnimation.RELATIVE_TO_SELF, 0.5f,
            RotateAnimation.RELATIVE_TO_SELF, 0.5f);
    rotate.setDuration(1000);
    rotate.setFillEnabled(true);
    rotate.setFillAfter(true);
    pt.startAnimation(rotate);
    pt.setRotation(pt.getRotation()+toDegrees);
    if (pt.getRotation() == 360) {
        pt.setRotation(0);
    }
}

共 (1) 个答案

  1. # 1 楼答案

    取全局变量-float rotation=0,fromRotation=0

    在Onclick上

                fromRotation=rotation;
                rotation = rotation + 90;
                RotatePoint(rotation);
    

    和旋转点(浮动到角度)

    RotateAnimation rotate = new RotateAnimation(fromRotation, toDegrees,
                Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        rotate.setDuration(1000);
    
    
        rotate.setFillAfter(true);
        pt.startAnimation(rotate);