如何顺时针旋转ImageView

时间:2015-02-05 16:58:53

标签: android animation android-activity android-fragments android-animation

我有一个向上滑动的面板,在该面板的标题栏中我有ImageView,如图所示。当用户向上滑动面板时,如何顺时针旋转到图像视图的180 *,向下滑动时,逆时针旋转到

为了滑动那个面板我有方法:

@Override
public void onPanelSlide(View panel, float slideOffset) {
     Log.i(TAG, "onPanelSlide, offset " + slideOffset);

     //Animation here
}

enter image description here

感谢您的帮助!

3 个答案:

答案 0 :(得分:1)

如果要在没有动画的情况下旋转视图:

  • view.setRotation(float)设置视图的度数 围绕枢轴点旋转。增加值会产生顺时针方向 转动。
  • view.setRotationX(float)设置视图的度数 通过枢轴点绕水平轴旋转。 从观点来看,增加值会导致顺时针旋转 向下看x轴。旋转大视图时,建议相应调整相机距离。

  • view.setRotationY(float)设置视图的度数 通过枢轴点绕垂直轴旋转。增加 从观点来看,值导致逆时针旋转 俯视y轴。旋转大视图时,建议相应调整相机距离。

如果你想使用动画:

答案 1 :(得分:0)

我不想将此标记为答案,但我还无法发表评论,我能够让Apurva的解决方案正常工作,但我不得不使用此代替getApplicationContext( ),我不得不使用这个,因为我设置动画的地方,我附加动画的应用程序中的代码看起来像这样......

ImageView billysArm = (ImageView) findViewById(R.id.imageView6);

    Animation rotate = AnimationUtils.loadAnimation(this, R.anim.rotate);

    billysArm.startAnimation(rotate);

希望这会有所帮助

答案 2 :(得分:0)

你应该尝试一下,为你的动画设置一个动画。 ImageView

@Override
public void onPanelSlide(View panel, float slideOffset) {
     Log.i(TAG, "onPanelSlide, offset " + slideOffset);

    // Locate view
    ImageView iv= (ImageView) findViewById(R.id.iv);

    // Create an animation instance
    Animation an = new RotateAnimation(0.0f, 180.0f, pivotX, pivotY);

    // Set the animation's parameters
    an.setDuration(10000);               // duration in ms
    an.setRepeatCount(0);                // -1 = infinite repeated
    an.setRepeatMode(Animation.REVERSE); // reverses each repeat
    an.setFillAfter(true);               // keep rotation after animation

    // Aply animation to image view
    iv.setAnimation(an);
}
相关问题