首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >循环浏览ImageView的位图

问循环浏览ImageView的位图
EN

Stack Overflow用户
提问于 2019-03-12 23:45:58
回答 1查看 44关注 0票数 0

通过python中的Flask,我已经向我的安卓应用程序发送了多张图片,并将它们存储到位图的ArrayList中

我如何在无限循环的淡出/淡入动画中自动循环它们?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-03-13 13:33:13

可以,您可以执行以下操作:(在这里,对于演示,我采用了一个可绘制的数组。您可以使用您的位图数组来代替它,或者将它用于演示。)

代码语言:javascript
复制
public class Main3Activity extends AppCompatActivity {


private ImageView imageView;
private int imageArray[] = { R.drawable.ic_launcher_background, R.drawable.ic_launcher_background,R.drawable.ic_launcher_background };

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main3);

    imageView = (ImageView) findViewById(R.id.imageView);

    startAnimation();
}

private void startAnimation() {


    int fadeInDuration = 500;
    int timeBetween = 3000;
    int fadeOutDuration = 1000;


    int random = new Random().nextInt((imageArray.length - 1) + 1);

    imageView.setVisibility(View.INVISIBLE);
    imageView.setImageResource(imageArray[random]);

    Animation fadeIn = new AlphaAnimation(0, 1);
    fadeIn.setInterpolator(new DecelerateInterpolator());
    fadeIn.setDuration(fadeInDuration);

    Animation fadeOut = new AlphaAnimation(1, 0);
    fadeOut.setInterpolator(new AccelerateInterpolator());
    fadeOut.setStartOffset(fadeInDuration + timeBetween);
    fadeOut.setDuration(fadeOutDuration);

    AnimationSet animation = new AnimationSet(false);
    animation.addAnimation(fadeIn);
    animation.addAnimation(fadeOut);
    animation.setRepeatCount(1);
    imageView.setAnimation(animation);

    animation.setAnimationListener(new Animation.AnimationListener() {
        public void onAnimationEnd(Animation animation) {
            startAnimation();
        }

        public void onAnimationRepeat(Animation animation) {
        }

        public void onAnimationStart(Animation animation) {
        }
    });

}
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55125570

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档