属性动画
来源:互联网 发布:服装成本统计软件 编辑:程序博客网 时间:2024/06/06 15:01
==========控件为imageview===============
public class MainActivity extends AppCompatActivity {
private ImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = findViewById(R.id.image_view);
}
public void trans(View view) {
ObjectAnimator animator = ObjectAnimator.ofFloat(imageView, "y", 0, 1300);
animator.setDuration(3000);
animator.setInterpolator(new AccelerateInterpolator());//加速的插值器
animator.start();
//监听事件
animator.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animator) {
}
@Override
public void onAnimationEnd(Animator animator) {
Toast.makeText(MainActivity.this,"结束,跳转页面",Toast.LENGTH_SHORT).show();
}
@Override
public void onAnimationCancel(Animator animator) {
}
@Override
public void onAnimationRepeat(Animator animator) {
}
});
}
public void rotrate(View view) {
ObjectAnimator animator = ObjectAnimator.ofFloat(imageView, "rotationY", 0, 360);
animator.setDuration(3000);
animator.start();
}
public void alpha(View view) {
ObjectAnimator animator = ObjectAnimator.ofFloat(imageView, "alpha", 0, 1);
animator.setDuration(3000);
animator.start();
}
public void scale(View view) {
ObjectAnimator animator = ObjectAnimator.ofFloat(imageView, "scaleX", 0, 2);
animator.setDuration(3000);
animator.start();
}
@SuppressLint("ObjectAnimatorBinding")
public void zuhe_01(View view) {
ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(imageView, "abc", 0, 1);
objectAnimator.setDuration(4000);
objectAnimator.start();
//动画的属性值不停更新的方法
objectAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
//属性的值
float animatedValue = (float) valueAnimator.getAnimatedValue();
imageView.setScaleX(animatedValue);
imageView.setScaleY(animatedValue);
imageView.setAlpha(animatedValue);
}
});
}
public void zuhe_02(View view) {
ObjectAnimator y = ObjectAnimator.ofFloat(imageView, "y", 0, 10, 200, 250, 500, 1000, 1100, 1300);
ObjectAnimator scaleX = ObjectAnimator.ofFloat(imageView, "scaleX", 0.5f, 2);
ObjectAnimator scaleY = ObjectAnimator.ofFloat(imageView, "scaleY", 0.5f, 2);
ObjectAnimator alpha = ObjectAnimator.ofFloat(imageView, "alpha", 0.5f, 1.0f);
ObjectAnimator rotationX = ObjectAnimator.ofFloat(imageView, "rotationX", 0, 360);
ObjectAnimator rotationY = ObjectAnimator.ofFloat(imageView, "rotationY", 0, 360);
AnimatorSet animatorSet = new AnimatorSet();
//设置
/*animatorSet.play(y).before(scaleX);
animatorSet.play(scaleX).with(scaleY);
animatorSet.play(alpha).with(scaleY);
animatorSet.play(rotationX).with(alpha).with(rotationY);*/
animatorSet.play(y).with(scaleX).with(scaleY).with(alpha);
animatorSet.setDuration(5000);
animatorSet.start();
animatorSet.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animator) {
}
@Override
public void onAnimationEnd(Animator animator) {
}
@Override
public void onAnimationCancel(Animator animator) {
}
@Override
public void onAnimationRepeat(Animator animator) {
}
});
}
}
===============从屏幕上部经历 移动 透明 旋转 伸缩 移到屏幕下部 =================
/** 组合动画* *///纵向移动ObjectAnimator y = ObjectAnimator.ofFloat(img, "y", 0, 300);//缩放ObjectAnimator scaleY = ObjectAnimator.ofFloat(img, "scaleY", 2, 1);ObjectAnimator scaleX = ObjectAnimator.ofFloat(img, "scaleX", 2, 1);//透明ObjectAnimator alpha = ObjectAnimator.ofFloat(img, "alpha", 0, 1); //旋转ObjectAnimator rotationX = ObjectAnimator.ofFloat(img, "rotationX", 0, 360);ObjectAnimator rotationY = ObjectAnimator.ofFloat(img, "rotationY", 0, 360);AnimatorSet animatorSet =new AnimatorSet();//进行设置 animatorSet.play(y).with(scaleX).with(scaleY).with(alpha).with(rotationX) ;//.with(rotationY)//设置时间animatorSet.setDuration(3000);animatorSet.start();//播放完成进行跳转animatorSet.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { // 跳转 Intent intent = new Intent(SplashActivity.this,XiangQingActivity.class); startActivity(intent); finish(); } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { }});
- 属性动画
- 属性动画
- 属性动画
- 属性动画
- 属性动画
- 属性动画
- 属性动画
- 属性动画
- 属性动画
- 属性动画
- 属性动画
- 属性动画
- 属性动画
- 属性动画
- 属性动画
- 属性动画
- 属性动画
- 属性动画
- PHP二维数组降一维函数
- AOP快速入门案例(四)
- Android Textview 添加下划线 方法
- linux(centos)升级到python3
- Intellij IDEA官方默认快捷键大全
- 属性动画
- 1004. 成绩排名 (20)-浙大PAT乙级真题java实现
- windows部署tomcat服务自动启动,及卸载服务
- linux 外接USB名和设备号转换
- jqGrid的常用属性和方法
- sm(spring+mybatis)注释版的整合
- 500 G JAVA视频网盘分享(JEECG开源社区)
- 指针变量
- color.xml资源文件