ObjectAnimator动画

灵动菜单
public class MainActivity extends AppCompatActivity {
private ImageView imageView;
private ImageView imageView1;
private ImageView imageView2;
private ImageView imageView3;
private ImageView imageView4;
private boolean isShow=true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = (ImageView) findViewById(R.id.image);
imageView1 = (ImageView) findViewById(R.id.image1);
imageView2 = (ImageView) findViewById(R.id.image2);
imageView3 = (ImageView) findViewById(R.id.image3);
imageView4 = (ImageView) findViewById(R.id.image4);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(isShow){
startAnim();
}else{
closeAnima();
}
}
});
}
private void closeAnima() {
ObjectAnimator animator=ObjectAnimator.ofFloat(imageView,”alpha”,0.5F,1F);
ObjectAnimator animator1=ObjectAnimator.ofFloat(imageView1,”translationY”,200f,0);
后面是可变参数,表明属性目标值,一个参数表明是终止值(对象要有get属性方法)
可变参数的个数为2时,表明第一个是起始值,第二个是终止值;更多个参数时,动画属性值会逐个经过这些值
//ObjectAnimator animator1=ObjectAnimator.ofFloat(imageView1,”translationY”,0);
ObjectAnimator animator2=ObjectAnimator.ofFloat(imageView2,”translationX”,200f,0);
ObjectAnimator animator3=ObjectAnimator.ofFloat(imageView3,”translationY”,-200f,0);
ObjectAnimator animator4=ObjectAnimator.ofFloat(imageView4,”translationX”,-200f,0);
AnimatorSet set=new AnimatorSet();
set.setDuration(1000);
set.setInterpolator(new BounceInterpolator());
set.playTogether(animator,animator1,animator2,animator3,animator4);
set.start();
isShow=true;
}
private void startAnim() {
// imageView.setTranslationX();
// imageView.setAlpha();
// imageView.setTranslationY();
ObjectAnimator animator=ObjectAnimator.ofFloat(imageView,”alpha”,1F,0.5F);
ObjectAnimator animator1=ObjectAnimator.ofFloat(imageView1,”translationY”,200F);
ObjectAnimator animator2=ObjectAnimator.ofFloat(imageView2,”translationX”,200F);
ObjectAnimator animator3=ObjectAnimator.ofFloat(imageView3,”translationY”,-200F);
ObjectAnimator animator4=ObjectAnimator.ofFloat(imageView4,”translationX”,-200F);
AnimatorSet set=new AnimatorSet();
set.setDuration(1000);
set.setInterpolator(new BounceInterpolator());
set.playTogether(animator,animator1,animator2,animator3,animator4);
set.start();
isShow=false;
这里可以以集合的形式添加图片
这里写图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值