Android change background image with fade in/out animation

前端 未结 5 1609
心在旅途
心在旅途 2020-12-29 08:47

I wrote code which can change background image random every 5 second.now i want to use fade in/out animation to change background image,but I do not know how I can use this

5条回答
  •  余生分开走
    2020-12-29 09:23

    For fade in animation , create new folder named 'anim' in your res folder and inside it, create 'fade_in.xml' with following code

    
    
    
        
    
    
    

    now to run this animation on your imageview, use following code in your activity

    Animation anim = AnimationUtils.loadAnimation(YourActivity.this, R.anim.fade_in);
    imageView.setAnimation(anim);
    anim.start();
    

    for fadeout animation, just swap values of android:fromAlpha and android:toAlpha

    Hope this helps.

提交回复
热议问题