垂直旋转ImageView

Sac*_*hin 4 xml animation android android-animation

我想水平翻转图像视图的动画(围绕x轴).我做了顺时针和逆时针动画.这是我用过的代码......

<set xmlns:android="http://schemas.android.com/apk/res/android"> 
    <rotate 
        android:fromDegrees="0" 
        android:toDegrees="180" 
        android:pivotX="50%" 
        android:pivotY="50%" 
        android:duration="300" 
        android:fillAfter="true" 
        android:fillEnabled="true" />
</set>
Run Code Online (Sandbox Code Playgroud)

我也想连续旋转它,它应该在每次翻转后暂停一会儿.

小智 6

尝试使用相应的Java逻辑跟踪XML代码,使用AnimationListener实现您的活动

animation1.xml

<?xml version="1.0" encoding="utf-8"?>
    <scale xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="250"
    android:fromXScale="1.0"
    android:fromYScale="1.0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toXScale="0.0"
    android:toYScale="1.0" />
Run Code Online (Sandbox Code Playgroud)

animation2.xml

<?xml version="1.0" encoding="utf-8"?>
     <scale xmlns:android="http://schemas.android.com/apk/res/android"
      android:duration="250"
      android:fromXScale="0.0"
      android:fromYScale="1.0"
      android:pivotX="50%"
      android:pivotY="50%"
      android:toXScale="1.0"
      android:toYScale="1.0" />
Run Code Online (Sandbox Code Playgroud)

Java逻辑

private Animation animation1, animation2;
animation1 = AnimationUtils.loadAnimation(this, R.drawable.to_middle);
animation1.setAnimationListener(this);
animation2 = AnimationUtils.loadAnimation(this, R.drawable.from_middle);
animation2.setAnimationListener(this);

     if (flag = true) {
        flipLayout.clearAnimation();
        flipLayout.setAnimation(animation1);
        flipLayout.startAnimation(animation1);
        flag = false;
    } else {
        flipLayout.clearAnimation();
        flipLayout.setAnimation(animation2);
        flipLayout.startAnimation(animation2);
        flag = true;
    }


@Override
public void onAnimationStart(Animation animation) {
    if (animation == animation1) {
        data = true;

    } else {
        if (id == true) {
            tv_calculation.setVisibility(View.GONE);
            id = false;
        } else {
            tv_calculation.setVisibility(View.VISIBLE);
            id = true;
        }
        data = false;
    }
}

@Override
public void onAnimationEnd(Animation animation) {

    if (animation == animation1) {

        flipLayout.clearAnimation();
        flipLayout.setAnimation(animation2);
        flipLayout.startAnimation(animation2);

    } else {

        flipLayout.clearAnimation();
        flipLayout.setAnimation(animation1);
        flipLayout.startAnimation(animation1);
    }

}
Run Code Online (Sandbox Code Playgroud)

FlipLayout是一个ImageView.