我想从左到右一张一张地为 9 张图像制作动画。我试过编码,所有图像都在同时移动。我需要一张一张地移动每张图片。
公共类 MainActivity 扩展 Activity {
ArrayList<ImageView> imageHolder;
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
animateBottles();
}
private void animateBottles() {
ImageView upperRowBottleOneImageView = (ImageView) findViewById(R.id.upperRowBottleOneImageView);
ImageView upperRowBottleTwoImageView = (ImageView) findViewById(R.id.upperRowBottleTwoImageView);
ImageView upperRowBottleThreeImageView = (ImageView) findViewById(R.id.upperRowBottleThreeImageView);
ImageView upperRowBottleFourImageView = (ImageView) findViewById(R.id.upperRowBottleFourImageView);
ImageView upperRowBottleFiveImageView = (ImageView) findViewById(R.id.upperRowBottleFiveImageView);
ImageView upperRowBottleSixImageView = (ImageView) findViewById(R.id.upperRowBottleSixImageView);
ImageView upperRowBottleSevenImageView = (ImageView) findViewById(R.id.upperRowBottleSevenImageView);
ImageView upperRowBottleEightImageView = (ImageView) findViewById(R.id.upperRowBottleEightImageView);
ImageView upperRowBottleNineImageView = (ImageView) findViewById(R.id.upperRowBottleNineImageView);
imageHolder = new ArrayList<ImageView>();
imageHolder.add(upperRowBottleOneImageView);
imageHolder.add(upperRowBottleTwoImageView);
imageHolder.add(upperRowBottleThreeImageView);
imageHolder.add(upperRowBottleFourImageView);
imageHolder.add(upperRowBottleFiveImageView);
imageHolder.add(upperRowBottleSixImageView);
imageHolder.add(upperRowBottleSevenImageView);
imageHolder.add(upperRowBottleEightImageView);
imageHolder.add(upperRowBottleNineImageView);
for (int i = 0; i < imageHolder.size(); i++) {
ImageView imageView = imageHolder.get(i);
ObjectAnimator mover = ObjectAnimator.ofFloat(imageView,
"translationX", -150f, 50f);
mover.setDuration(4000);
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.play(mover);
animatorSet.start();
mover.addListener(new AnimatorListener() {
@Override
public void onAnimationCancel(Animator arg0) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animator arg0) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animator arg0) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationStart(Animator arg0) {
// TODO Auto-generated method stub
}
});}
//try {
//Thread.sleep(1000);
//} catch (InterruptedException e) {
// // TODO Auto-generated catch block
//e.printStackTrace();
//}
//}
}
@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;
}
}