Android Change picture every 10 seconds

前端 未结 4 593
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-24 09:14

Im trying to write a very basic android app that displays around 5 pictures one after each other on the screen. I want it to display a different picture after about 10 secon

4条回答
  •  天命终不由人
    2020-12-24 09:24

    Have you considered using Frame Animations?

    You can specify an xml in your anim folder that contains a frame-by-frame animation, specifing each image duration, and other settings, check it out

    UPDATE

    You can also build a frame animation programmatically of course:

        AnimationDrawable animation = new AnimationDrawable();
        animation.addFrame(getResources().getDrawable(R.drawable.image1), 100);
        animation.addFrame(getResources().getDrawable(R.drawable.image2), 500);
        animation.addFrame(getResources().getDrawable(R.drawable.image3), 300);
        animation.setOneShot(false);
    
        ImageView imageAnim =  (ImageView) findViewById(R.id.img);
        imageAnim.setBackgroundDrawable(animation);
    
        // start the animation!
        animation.start()
    

提交回复
热议问题