感谢慕课网--
布局文件:activity_main.xml
16 7 14 15 22 23 30 31 38 39 46 47 54 55 62 63 68 69
图片资源
MainActivity.java
1 package com.example.animationapp; 2 3 import java.util.ArrayList; 4 import java.util.List; 5 6 import android.support.v7.app.ActionBarActivity; 7 import android.animation.ObjectAnimator; 8 import android.os.Bundle; 9 import android.view.Menu;10 import android.view.MenuItem;11 import android.view.View;12 import android.view.View.OnClickListener;13 import android.view.animation.BounceInterpolator;14 import android.widget.ImageView;15 import android.widget.Toast;16 17 public class MainActivity extends ActionBarActivity implements OnClickListener {18 19 private int[] res = {R.id.im0, R.id.im1,R.id.im2,20 R.id.im3,R.id.im4,R.id.im5,R.id.im6,R.id.im7}; 21 22 private Listlist = new ArrayList (); 23 24 private boolean flag = true;25 26 @Override27 protected void onCreate(Bundle savedInstanceState) {28 super.onCreate(savedInstanceState);29 setContentView(R.layout.activity_main);30 31 initView();32 }33 34 private void initView() {35 36 for(int i = 0; i < res.length; i++){37 ImageView im = (ImageView) findViewById(res[i]);38 im.setOnClickListener(this);39 list.add(im);40 }41 }42 43 @Override44 public void onClick(View v) {45 switch(v.getId()){46 //im7最后布局,叠加在最上面47 case R.id.im7:{48 49 if(flag){50 startAnimation();51 flag = false;52 }else{53 closeAnimation();54 flag = true;55 }56 break;57 }58 59 default:60 Toast.makeText(MainActivity.this, v.getId()+"OK", Toast.LENGTH_SHORT).show();61 break;62 }63 }64 65 private void closeAnimation() {66 for(int i = 0 ;i