繁体   English   中英

Java-使用FadeIn和FadeOut动画进行无尽的while循环

[英]Java - Endless while loop with FadeIn & FadeOut animation

我需要使用FadeIn和FadeOut动画在Recyclerview上显示文本。

以下是需要循环无限项的动态列表,即; 1-2-3-1-2-3-1-2-3

List<String> mImageDesc = new List<String>();
mImageDesc.add("1");
mImageDesc.add("2");
mImageDesc.add("3");

我使用了下面的代码,但对我不起作用。

final  Animation animationFadeIn = AnimationUtils.loadAnimation(mContext, R.anim.fade_in_animation);
        final Animation animationFadeOut = AnimationUtils.loadAnimation(mContext, R.anim.fade_out_animation);

        Animation.AnimationListener animListener = new Animation.AnimationListener(){

            // Required to change the image
            int i = 0;

            @Override
            public void onAnimationStart(Animation animation) {
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }

            @Override
            public void onAnimationEnd(Animation animation) {

                if (animation == animationFadeIn) {
                    // Start fade-out animation
                    mTxtImageDescription.startAnimation(animationFadeOut);
                } else if (animation == animationFadeOut) {
                    *while(mImageDesc.listIterator().hasNext()) {
                        System.out.println(mImageDesc.listIterator().next());
                        mTxtImageDescription.setText(mImageDesc.listIterator().next());
                        mTxtImageDescription.startAnimation(animationFadeIn);*
                    }
                }
            }
        };

        // Set listener to animation
        animationFadeIn.setAnimationListener(animListener);
        animationFadeOut.setAnimationListener(animListener);

        // Start fade-in animation
        mTxtImageDescription.setText(mImageDesc.get(0));
        mTxtImageDescription.startAnimation(animationFadeIn);

在while循环的最后一行中,您已经重新启动了'animationFadeIn',因此将永远调用'animListener'回调。请注意,如果while循环是重复执行,则将出现'StackOverflowError'。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM