I had used the following approach in order to give animation in my application. There can be many other ways. I had done this...
Do this in xml.
<RelativeLayout
android:id="@+id/gradient_rl"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/profile_gradient4">
<!-- place your child views here-->
<Relativelayout/>
In drawable make a xml layout.
profile_gradient4.xml
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@drawable/profile_gradient1"
android:duration="7500"/>
<item
android:drawable="@drawable/profile_gradient2"
android:duration="7500"/>
<item
android:drawable="@drawable/profile_gradient3"
android:duration="7500"/>
</animation-list>
You can get code for profile_gradient1, 2, 3 from here ->My app which runs a smooth animation in background.
Those xml are present in drawable folder. You may even use normal images instead of these 3 xml layouts.
In java code inside your activty:
private void runGradient() {
//method is used to give gradient color animation to the bottom of profile screen
RelativeLayout relativeLayout = findViewById(R.id.gradient_rl);
AnimationDrawable animationDrawable = (AnimationDrawable) relativeLayout.getBackground();
animationDrawable.setEnterFadeDuration(5000);
animationDrawable.setExitFadeDuration(7500);
animationDrawable.start();
}
What was I doing above?
The relative layout I made will have the background for my child views.
In profile_gradient4.xml, I made an animation list consisting of 3 other drawables. They are profile_gradient1, 2 and 3.
Then inside my activity, I got my animation list using AnimatonDrawable, gave entry and exit fade animation time and started the animation of profile_gradient1, 2 and 3.
You can use and run my app from GitHub link above.
Edit : Other suggestive approaches ->
If you want a gif animation to be your background, this article might help you->adding-gif-image-in-an-imageview-in-android.
You can also use some libraries like glide to display gif. Make that gif view span the size of its parent view and then draw other child views above that gif view.