【问题标题】:Rotate animation from centre of view not working从视图中心旋转动画不起作用
【发布时间】:2014-10-07 12:21:54
【问题描述】:

我想为我的视图制作一个旋转动画,但是在两边(java 和 xml)我找不到任何方法来从它的中心旋转视图

<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:repeatMode="reverse"
android:toDegrees="180" />

还有这个:

RotateAnimation animation = new RotateAnimation(0,180,
            Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
            0.5f);

它们都从角落旋转视图

请帮帮我

【问题讨论】:

    标签: android pivot center rotateanimation


    【解决方案1】:

    看起来您尝试旋转所有布局,而不是视图。你需要的。 工作代码

    View view = findViewById( R.id.image );
    aRotate = new RotateAnimation(fStartAngle, fEndAngle,
              Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
    
    aRotate.setStartOffset(0);
    aRotate.setDuration(2000);
    aRotate.setFillAfter(true);
    aRotate.setInterpolator(context, android.R.anim.decelerate_interpolator);
    
    view.startAnimation(aRotate);
    

    【讨论】:

    • 谢谢!我在使用 view.setAnimation 而不是 view.startAnimation 时遇到问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多