我想创建使用三个动画ImageViews是旋转和缩放到屏幕上,通过按钮触发一个简单的“3-2-1”倒计时。我对单个ImageView的动画没有问题,但是我无法顺序执行3 ...然后2 ...然后1帧。谁能帮忙? 下面是在MainActivity简化布局XMLAndroid的 - 连续循环的N帧动画,同时改变ImageViews
<Button
android:id="@+id/go_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/rotate"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="120dp"
android:text="GO!" />
<ImageSwitcher
android:id="@+id/imageSwitcher"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="220dp" />
这里是我的XML配置的动画之一(这一个缩小了的ImageView出):
<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator"
android:startOffset="0"
android:fromXScale="5.0"
android:toXScale="1.0"
android:fromYScale="5.0"
android:toYScale="1.0"
android:duration="600"
android:pivotX="50%"
android:pivotY="50%" >
</scale>
,这里是在MainActivity的Java文件:
public class MainActivity extends ActionBarActivity {
private Button animateCountdown;
private ImageSwitcher myImageSwitcher;
private static final int[] IMAGES = { R.drawable.icon_3, R.drawable.icon_2, R.drawable.icon_1};
private int currentIMAGESIndex = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myImageSwitcher = (ImageSwitcher) findViewById(R.id.imageSwitcher);
myImageSwitcher.setFactory(new ViewSwitcher.ViewFactory() {
@Override
public View makeView() {
ImageView imageView = new ImageView(MainActivity.this);
return imageView;
}
});
animateCountdown = (Button) findViewById(R.id.go_button);
animateCountdown.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
runCountdownAnimation(view);
}
});
}
private void runCountdownAnimation(View view){
//Using an animation set, to allow for concurrent animations.
AnimationSet animationSet = getCountdownAnimationSet();
Animation fadeOutAnimation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fade_out);
myImageSwitcher.setInAnimation(animationSet);
myImageSwitcher.setOutAnimation(fadeOutAnimation);
while(currentIMAGESIndex < (IMAGES.length - 1)){
myImageSwitcher.setImageResource(IMAGES[currentIMAGESIndex]);
currentIMAGESIndex++;
myImageSwitcher.postDelayed(this, 1000);
}
我使用的动画集,以运行变焦,阿尔法兼旋转动画。到目前为止,我曾试图改变ImageView的来源,并重新启动从动画听众的onAnimationEnd()内的动画......但没有运气。循环遍历数组中的图像也不起作用。
我如何循环动画的3倍,但在每次迭代结束改变ImageView的?在最后一次迭代结束时,我想创建一个Intent并加载一个新的活动。
感谢提前:)
更新......这里的getCountDownAnimationSet()代码:
private AnimationSet getCountdownAnimationSet(){
Animation rotateAnimation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.rotate);
Animation fadeAnimation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fade_in);
Animation zoomAnimation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.zoom);
AnimationSet animationSet = new AnimationSet(false); //false means don't share interpolators
animationSet.addAnimation(rotateAnimation);
animationSet.addAnimation(fadeAnimation);
animationSet.addAnimation(zoomAnimation);
return animationSet;
}
好吧,这是一个相当复杂的方法,的东西,似乎是相当简单的。第一:很少的事情。为什么你需要一个'ImageSwitcher'?向我们展示'getCountdownAnimationSet()'的代码。 –