当我展开动画还没结束,执行收起动画的时候,有的button没有收回,谁帮忙看看
package com.example.animationdemo;
import java.sql.Date;
import java.sql.Time;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.util.TimeUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.BounceInterpolator;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.Toast;
public class MainActivity extends Activity {
ImageView img;
int[] imgList = {R.id.menuBtn1,R.id.menuBtn2,R.id.menuBtn3,R.id.menuBtn4,R.id.menuBtn5,R.id.menuBtn6,R.id.menuBtn7,R.id.menuBtn8,};
ArrayList<ImageButton> imgBtnList = new ArrayList<ImageButton>();
boolean isEx = false;
float winHeigth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
img = (ImageView) findViewById(R.id.anmImg);
for (int i = 0; i < imgList.length; i++) {
ImageButton imgBtn = (ImageButton) findViewById(imgList[i]);
imgBtnList.add(imgBtn);
}
winHeigth = getResources().getDisplayMetrics().heightPixels;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public void start(View view){
ObjectAnimator.ofFloat(img, "translationX", 0,100F).setDuration(2000).start();
PropertyValuesHolder animator1 = PropertyValuesHolder.ofFloat("translationY", 0,100F);
PropertyValuesHolder animator2 = PropertyValuesHolder.ofFloat("rotation", 0,360F);
ObjectAnimator.ofPropertyValuesHolder(img, animator1,animator2).start();
ObjectAnimator a1 = ObjectAnimator.ofFloat(img, "translationX", 0,100F).setDuration(2000);
ObjectAnimator a2 = ObjectAnimator.ofFloat(img, "translationY", 0,100F).setDuration(2000);
ObjectAnimator a3 = ObjectAnimator.ofFloat(img, "rotation", 0,360F).setDuration(2000);
// AnimatorSet set = new AnimatorSet();
// set.play(a1).with(a2);
// set.play(a3).after(a1);
// set.start();
}
public void menuOnClick(View v){
switch (v.getId()) {
case R.id.menuBtn8:
if (isEx) {
foldMenu();
isEx = false;
}else {
unfoldMenu();
isEx = true;
}
break;
default:
Toast.makeText(this, "menu"+v.toString(), Toast.LENGTH_SHORT).show();
break;
}
}
private void unfoldMenu() {
// TODO Auto-generated method stub
ImageButton orderBtn = imgBtnList.get(imgBtnList.size()-1);
for (int i = 0; i < imgBtnList.size() - 1; i++) {
ImageButton menu = imgBtnList.get(i);
float moveLen = (winHeigth - orderBtn.getTranslationY()) / 10 * (i+1);
float time = (winHeigth - orderBtn.getTranslationY()) / 10/winHeigth*3000;
float startY;
if (i == 0) {
startY = imgBtnList.get(imgBtnList.size()-1).getTranslationY();
}else {
startY = imgBtnList.get(i-1).getY();
}
ObjectAnimator animator1 = ObjectAnimator.ofFloat(menu, "translationY", startY,moveLen+orderBtn.getTranslationY());
// animator1.setInterpolator(new BounceInterpolator());
animator1.setStartDelay((long) time*(i+1));
animator1.setDuration((long) time);
animator1.start();
}
}
private void foldMenu() {
// TODO Auto-generated method stub
long start = System.currentTimeMillis();
for (int i = 0; i < imgBtnList.size() - 1; i++) {
ImageButton menu = imgBtnList.get(i);
menu.clearAnimation();
float moveLen = imgBtnList.get(imgBtnList.size()-1).getTranslationY();
ObjectAnimator animator1 = ObjectAnimator.ofFloat(menu, "translationY", menu.getTranslationY(),moveLen);
animator1.setDuration((long) (3000*((menu.getTranslationY()-moveLen)/winHeigth)));
animator1.start();
}
long end = System.currentTimeMillis();
Log.i("test", "Time:"+(end-start));
}
}