猿问

安卓动画可自行旋转图像

我想制作一个动画,以便在自身上旋转图像(通过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);

}


慕码人2483693
浏览 182回答 2
2回答

BIG阳

这是答案,尽管它仅适用于3.0及更高版本。1)创建一个名为“动画师”的新资源文件夹。2)创建一个新的.xml文件,我称之为“翻转”。使用以下 XML 代码:<?xml version="1.0" encoding="utf-8"?><objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"&nbsp; &nbsp; android:valueFrom="0" android:valueTo="360" android:propertyName="rotationY" ></objectAnimator>不可以,对象动画器标记不以大写字母“O”开头。3) 使用以下代码开始动画:ObjectAnimator anim = (ObjectAnimator) AnimatorInflater.loadAnimator(mContext, R.animator.flipping);&nbsp;anim.setTarget(A View Object reference goes here i.e. ImageView);anim.setDuration(3000);anim.start();

翻阅古今

这是一个伟大的图书馆与一堆动画。尝试YoYo动画任何类型的视图。在应用程序的生成.gradle 文件中添加以下依赖项dependencies {&nbsp; &nbsp; &nbsp; &nbsp; compile 'com.android.support:support-compat:25.1.1'&nbsp; &nbsp; &nbsp; &nbsp; compile 'com.daimajia.easing:library:2.0@aar'&nbsp; &nbsp; &nbsp; &nbsp; compile 'com.daimajia.androidanimations:library:2.3@aar'}例:YoYo.with(Techniques.FlipOutY).duration(700).repeat(5)&nbsp; &nbsp;// If you want to do INFINITELY then set "-1" value here.playOn(findViewById(R.id.edit_area));
随时随地看视频慕课网APP

相关分类

Java
我要回答