android 动画在自身上旋转图像
android animation rotate an Image on itself
我想制作一个动画来旋转图像(通过 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);
}
这是答案,尽管它仅适用于 3.0 及更高版本。
1) 创建一个名为 "animator" 的新资源文件夹。
2) 创建一个新的 .xml 文件,我将其命名为 "flipping"。使用以下 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();
这里是带有大量动画的大图书馆。
为任何类型的视图尝试 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));
我想制作一个动画来旋转图像(通过 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);
}
这是答案,尽管它仅适用于 3.0 及更高版本。
1) 创建一个名为 "animator" 的新资源文件夹。
2) 创建一个新的 .xml 文件,我将其命名为 "flipping"。使用以下 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();
这里是带有大量动画的大图书馆。
为任何类型的视图尝试 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));