ObjectAnimator动画

来源:互联网 发布:淘宝蜂蜜类目怎么选择 编辑:程序博客网 时间:2024/05/11 23:49

灵动菜单
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
原创粉丝点击