【问题标题】:android animation rotate an Image on itselfandroid动画在自身上旋转图像
【发布时间】:2019-04-04 17:45:29
【问题描述】:

我想制作一个动画,以便在自身上旋转图像(通过 x 轴)。

完全像这样:

我之前没有找到类似的东西,我已经尝试了一些技巧,例如:

public static void coinAnimation(final View v){
    RotateAnimation anim = new RotateAnimation(0.0f, 360.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
    anim.setInterpolator(new LinearInterpolator());
    anim.setRepeatCount(Animation.INFINITE);
    anim.setDuration(700);


    v.startAnimation(anim);

    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            v.setAnimation(null);

        }
    }, 2000);
}

【问题讨论】:

标签: java android animation android-animation


【解决方案1】:

这是答案,虽然它只适用于 3.0 及更高版本。

1) 创建一个名为“animator”的新资源文件夹。

2) 创建一个新的 .xml 文件,我将其称为“翻转”。使用以下 XML 代码:

<?xml version="1.0" encoding="utf-8"?>
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
    android:valueFrom="0" android:valueTo="360" android:propertyName="rotationY" >
</objectAnimator>

不,objectAnimator 标签不以大写“O”开头。

3) 使用以下代码启动动画:

ObjectAnimator anim = (ObjectAnimator) AnimatorInflater.loadAnimator(mContext, R.animator.flipping); 
anim.setTarget(A View Object reference goes here i.e. ImageView);
anim.setDuration(3000);
anim.start();

【讨论】:

    【解决方案2】:

    这是带有大量动画的大图书馆。

    为任何类型的视图尝试YoYo 动画。

    在应用程序的 build.gradle 文件中添加以下依赖项

    dependencies {
            compile 'com.android.support:support-compat:25.1.1'
            compile 'com.daimajia.easing:library:2.0@aar'
            compile 'com.daimajia.androidanimations:library:2.3@aar'
    }
    

    示例:

    YoYo.with(Techniques.FlipOutY)
    .duration(700)
    .repeat(5)   // If you want to do INFINITELY then set "-1" value here
    .playOn(findViewById(R.id.edit_area));
    

    【讨论】:

    • 我试过了但是硬币只转了一半开始消失然后从头开始
    猜你喜欢
    • 2014-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-01
    • 1970-01-01
    • 2021-09-27
    • 2021-02-07
    • 1970-01-01
    相关资源
    最近更新 更多