How To Add Responsive Animation In Splash Activity In Android Studio

Add Responsive Animation In Splash Activity In Android StudioAdding animation in your Splash Activity makes it look more responsive and premium. Add a responsive, fresh animation with ImageView [Animation as like: the app is loading] in your Splash Activity in Android Studio. it will make your splash activity look more responsive. But for doing this you must have created a splash activity before the follow our steps.

This Article Includes these also:

  • Adding Animation in ImageView
  • Blink Animation in Android Studio
  • etc
So, If you don't know how to create a splash activity in Android Studio then you can read this article:
How To Create A Splash Activity In Android Studio

Before we get started we need These:
  • Android Studio
  • An existing App project with a Splash Activity

So, we are all set. Let's Get Started.....



Step 1 - Creating An Blink Animation Resource File:

First of all,
  1. Create a New Directory named 'anim' in the folder 'res'.
  2. In the 'anim' directory, create a new Animation Resource File. You can name it anything (e.g. blink)
As we want our image logo to blink, we will use Alpha and set some attributions as shown below in the Animation resource file:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:duration="1000"
android:repeatMode="reverse"
android:repeatCount="infinite"/>
</set>

We set 'interpolator' to acceleration and repeat mode to 'reverse' as we want to make it reveal and disappear. We set repeat count to 'infinite' as we don't want the animation stop. You can set the repeat count to 3-4 or more as you want.

So, We Have Successfully Created An Animation Resource File. You can Clear any Doubt in the comment section.

Now we need to set this animation to our ImageView.

Step 2 - Adding Animation To ImageView:

We will go to our Splash Activity Java File (e.g. YOUR_ACTIVITY.java). Now we need to import these classes along with other imports to use ImageView and Animation:
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

And add these lines also inside the 'public class MainActivity' and before the 'OnCreate' :
public ImageView imageView;
Animation animation;

Now in 'OnCreate' we will find our ImageView by it's id. so, check your xml and copy the id you given to it (if not added yet, then in the ImageView, add this attribution: android:id="@+id/applogo" ):
imageView = findViewById(R.id.applogo);

Simply change the "applogo" with your image file name located at the Drawable folder.

Now we will load and set the animation to our ImageView By adding this Lines:
animation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.blink);
imageView.setAnimation(animation);

Simply change the "blink" with your animation resource file name located at the Drawable folder.

So, Coding Completed. Our Complete ACTIVITY_NAME.java file will look like this:
...
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {
...
public ImageView imageView;
Animation animation;

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

imageView = findViewById(R.id.applogo);
animation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.blink);
imageView.setAnimation(animation);

...

}
}

CONGRATS!!
We Have Successfully Created A Responsive Splash Activity

Thanks For Allowing Us To Help You :)
If you are confused or want to know something, then let us know in the comment box, we will reach you as soon as possible. Don't Forget To Subscribe our Newsletter, YouTube Channel, and Like Our Facebook Page To Keep Updated With Awesome Things. Follow us on Twitter to stay updated with the latest news & changes.

Comments

  1. thank you. can you please write an article on how to check internet?

    ReplyDelete
You are always welcome to ask us and share your ideas
We try to bring to you the most amazing learning site for tech enthusiasts and thus work to teach you the basic and internal parts of software management, website and apps making, programming, etc. Programming and technical explications are the main points and we hereby provide you the requisite basic and a clear idea about programming and other technological interests. Our main purpose is to make you fluent in programming languages.

Subscribe