1 public class TestActivity extends Activity implementsOnClickListener{2 private int[] res={R.id.imageView1,R.id.imageView2,R.id.imageView3,R.id.imageView4,R.id.imageView5,R.id.imageView6};3 private List list=new ArrayList();4 private booleanflag;5 @Override6 protected voidonCreate(Bundle savedInstanceState) {7 //TODO Auto-generated method stub
8 super.onCreate(savedInstanceState);9 setContentView(R.layout.tests);10 for(int i=0;i
16 }17 /**
18 public void move(View view){19 ImageView iv=(ImageView) findViewById(R.id.imageView1);20 //属性动画21 // ObjectAnimator.ofFloat(iv, "translationX", 0,200f).setDuration(1000).start();//X轴移动22
23 //第2种 优化24 // PropertyValuesHolder p1=PropertyValuesHolder.ofFloat("translationX", 0,200f);25 // PropertyValuesHolder p2=PropertyValuesHolder.ofFloat("translationY", 0,200f);26 // PropertyValuesHolder p3=PropertyValuesHolder.ofFloat("rotation", 0,360f);27 // ObjectAnimator.ofPropertyValuesHolder(iv, p1,p2,p3).setDuration(1000).start();28
29 //结合30 AnimatorSet set=new AnimatorSet();31 ObjectAnimator oa1=ObjectAnimator.ofFloat(iv, "translationX", 0,200f);32 ObjectAnimator oa2=ObjectAnimator.ofFloat(iv, "translationY", 0,200f);33 ObjectAnimator oa3=ObjectAnimator.ofFloat(iv, "rotation", 0,360f);34 // set.playTogether(oa1,oa2,oa3);//一起35 // set.playSequentially(oa1,oa2,oa3);//顺序播放36 set.play(oa1).with(oa2);37 set.play(oa3).after(oa2);//平移在一起,最后在旋转38 set.setDuration(1000);39 set.start();40 }41 */
42
43 @Override44 public voidonClick(View v) {45 switch(v.getId()) {46 caseR.id.imageView1:47 if(flag){48 startAnimat();49 }else{50 closeAnimat();51 }52 break;53
54 default:55 Toast.makeText(this, "click"+v.getId(), Toast.LENGTH_SHORT).show();56 break;57 }58
59 }60 private voidcloseAnimat() {61 for(int i=1;i
69 set.start();70 flag=true;71
72 }73
74 }75 /**
76 * 菜单展开77 */
78 private voidstartAnimat() {79 //TODO Auto-generated method stub
80 for(int i=1;i
87 set.start();88 flag=false;89
90 }91 }92
93 /**
94 * 监听事件95 */
96 //public void move(View view){97 //ObjectAnimator oa1=ObjectAnimator.ofFloat(view, "alpha", 0,1f);98 //oa1.setDuration(1000).start();99 //oa1.addListener(new AnimatorListenerAdapter() {100 //@Override101 //public void onAnimationEnd(Animator animation) {102 //Toast.makeText(TestActivity.this,"click", Toast.LENGTH_SHORT).show();103 //}104 //});105 //}
106 }