圆周轨迹动画:
<span style="font-size:18px;"> protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ImageView image = (ImageView) this.findViewById(R.id.image);
Button btn = (Button) this.findViewById(R.id.btn);
final ValueAnimator animator = ValueAnimator.ofFloat(0, 360);
animator.setDuration(1500);
animator.setInterpolator(new LinearInterpolator());
animator.addUpdateListener(new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator anim) {
float i = (Float) anim.getAnimatedValue();
image.setX(-(1 - i / 360) * 100
* (float) Math.sin(i * Math.PI / 180));
image.setY(-(1 - i / 360) * 100
* (float) Math.cos(i * Math.PI / 180));
image.setAlpha(i);
// image.setScaleX(i);
// image.setScaleY(i);
}
});
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// image.startAnimation(rotate);
animator.cancel();
animator.start();
}
});
}
}
</span>
2 浮标动画:
<span style="font-size:18px;">package com.example.animation;
import android.animation.TypeEvaluator;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.app.Activity;
import android.graphics.PointF;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.CycleInterpolator;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ImageView image = (ImageView) this.findViewById(R.id.image);
final Button btn = (Button) this.findViewById(R.id.btn);
//加载anim文件 的xml
final Animation animation=AnimationUtils.
loadAnimation(this, R.anim.tween_animation);
animation.setDuration(2000);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// image.startAnimation(rotate);
image.startAnimation(animation);
}
});
}
}
</span>
<span style="font-size:18px;"><?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="1000"
android:fromXDelta="0"
android:fromYDelta="-15"
android:repeatCount="infinite"
android:toXDelta="0"
android:toYDelta="20" />
<alpha
android:duration="1000"
android:fromAlpha="1.0"
android:repeatCount="infinite"
android:toAlpha="0.3" />
</set></span>
3 组合动画 旋转
<span style="font-size:18px;"><set xmlns:android="http://schemas.android.com/apk/res/android" >
<scale
android:duration="800"
android:fillAfter="false"
android:fromXScale="0.0"
android:fromYScale="0.0"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="1.2"
android:toYScale="1.2" />
<rotate
android:duration="3000"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="-1"
android:toDegrees="359.0" />
</set> </span>
4 摇摆动画<span style="font-size:18px;"> int pivot = Animation.RELATIVE_TO_SELF;
CycleInterpolator interpolator = new CycleInterpolator(3.0f);
final RotateAnimation animation = new RotateAnimation(0, 10, pivot,
0.47f, pivot, 0.05f);
animation.setStartOffset(500);
animation.setDuration(3000);
animation.setRepeatCount(1);// Animation.INFINITE
animation.setInterpolator(interpolator); </span>
5 一个角度摇摆
RELATIVE_TO_PARENT
<span style="font-size:18px;">int pivot=RELATIVE_TO_PARENT 换成这个参数</span>