Animation
程序员文章站
2024-01-19 13:47:46
...
package com.bawei.animation;
import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private ImageView img;
private TextView text;
private Animator animator;
private AnimatorSet animatorSet;
private ValueAnimator valueAnimator;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
img = findViewById(R.id.img);
text = findViewById(R.id.txet);
initAnimatorSet();
initvalueAnimatar();
}
private void initAnimatorSet() {
ObjectAnimator alpha = ObjectAnimator.ofFloat(img, "alpha", 0f, 360f);
ObjectAnimator translationX = ObjectAnimator.ofFloat(img, "translationX", 0f, 360f);
ObjectAnimator translationY = ObjectAnimator.ofFloat(img, "translationY", 0f, 360f);
ObjectAnimator rotation = ObjectAnimator.ofFloat(img, "rotation", 0f, 360f);
animatorSet = new AnimatorSet();
animatorSet.play(rotation)
.with(alpha)
.before(translationY)
.after(translationX);
animatorSet.setDuration(5000);
animatorSet.start();;
}
private void initvalueAnimatar() {
valueAnimator = ValueAnimator.ofInt(100,500,100,500,600,800);
valueAnimator.setDuration(5000);
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
int animatedValue;
animatedValue = (int) animation.getAnimatedValue();
text.layout(animatedValue,animatedValue,animatedValue+text.getWidth(),animatedValue+text.getHeight());
}
});
valueAnimator.start();
}
private void initObjAnimatar(String state) {
animator = ObjectAnimator.ofFloat(img,state,1f,5f,1f);
animator.setDuration(5000);
animator.start();
}
}
上一篇: animation
推荐阅读
-
Animation
-
Animation
-
animation
-
Animation
-
Flutter The argument type ‘Listenable‘ can‘t be assigned to the parameter type ‘Animation<double>
-
Animation
-
安卓三种动画之一View Animation与 案例 为活动的载入与退出添加动画
-
Flutter笔记二 ----Animation
-
Flutter之通过AnimationController源码分析学习使用Animation
-
用matplotlib中的animation.FuncAnimation画动态图