Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/374.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android-在更改ImageView时连续循环N帧动画_Java_Android_Animation_Imageswitcher - Fatal编程技术网

Java Android-在更改ImageView时连续循环N帧动画

Java Android-在更改ImageView时连续循环N帧动画,java,android,animation,imageswitcher,Java,Android,Animation,Imageswitcher,我想创建一个简单的“3-2-1”倒计时,使用三个在屏幕上旋转和缩放的动画图像视图,由一个按钮触发。我对单个ImageView的动画没有问题,但我无法连续执行3。。。然后2。。。然后是1帧。有人能帮忙吗? 以下是MainActivity的简化布局XML <Button android:id="@+id/go_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layo

我想创建一个简单的“3-2-1”倒计时,使用三个在屏幕上旋转和缩放的动画图像视图,由一个按钮触发。我对单个ImageView的动画没有问题,但我无法连续执行3。。。然后2。。。然后是1帧。有人能帮忙吗? 以下是MainActivity的简化布局XML

<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" />

好的。。。所以我把它分类了。我用了一个安卓倒计时

private void initialiseCountdownTimer(long timerDuration, long timerInterval){
    countDownTimer = new CountDownTimer(timerDuration, timerInterval) {
        @Override
        public void onTick(long millisUntilFinished) {
            if(!countdownImageStack.empty()){
                countdownImage.setImageResource(countdownImageStack.pop());
                countdownImage.startAnimation(countdownAnimationSet);

            }

        }
我使用了一个包含图像引用的堆栈(用作动画中的关键帧)。每次勾选时,我都会弹出堆栈来切换图像文件。我通过onClick()方法启动了倒计时


结果如何?没有令人讨厌的并发问题-但我仍然使用动画集,以便同时旋转和缩放

好的,这是一个相当复杂的方法,对于一些看起来相当简单的东西。第一:没什么。为什么需要
图像切换器
?显示
getCountdownAnimationSet()
的代码。
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);
     }
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;
}
private void initialiseCountdownTimer(long timerDuration, long timerInterval){
    countDownTimer = new CountDownTimer(timerDuration, timerInterval) {
        @Override
        public void onTick(long millisUntilFinished) {
            if(!countdownImageStack.empty()){
                countdownImage.setImageResource(countdownImageStack.pop());
                countdownImage.startAnimation(countdownAnimationSet);

            }

        }