Android change background image with fade in/out animation

前端 未结 5 1595
心在旅途
心在旅途 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条回答
  •  旧时难觅i
    2020-12-29 09:09

    You can use relativeLayout, and add one layer of background view which set both height and width match_parent. All other UI element should put on top of this view. In your code. Define fadeOut and fadeIn animation. Find that background view by id, then do this:

     xxxBackground.startAnimation(fadeOut);
     xxxBackground.setBackgroundResource(R.drawable.your_random_pic);
     xxxBackground.startAnimation(fadeIn);
    

    You can use some interpolator to tune the performance.

提交回复
热议问题