Overview Of View Animator In Android

Introduction

In this blog, you will learn how to create View Animator apps in Android, using Android Studio. Now, more and more applications are mainly used for animation because the animation is a good graphical user interface.

Requirements

  • Windows 10 (OS is free available source in online (https//www.microsoft.com/en-in/software-download/windows10). 

  • Android Studio 2.1.3 (free source available in online (https//developer.android.com/studio/index.html?gclid=CNP3qbH5htECFdiKaAodeFIKtA)

If you want develop ViewAnimator app, it should follow the steps given below.

Step 1

First of all, you will open Android Studio and you can go to the file. Select New and click NewProject.

ViewAnimator

Step 2

Now, you will write the Application's name and choose a file saving location. Afterwards, you click the Next button.

ViewAnimator

Step 3

Now, you will click select the form factors and your app will run on the different platforms which may require separate SDKs, which is like Phone and Tablet Minimum SDK (API 16Android 4.1(Jellybean)) and afterwards, you will click the Next button.

ViewAnimator

Step 4

Now, you will choose Activity, which is like (Basic Activity,Empty activity, extra) and click the next button.

ViewAnimator

Here, you will write the activity name and click finish button.

ViewAnimator

Step 5

Now, open your project and you will go to activity_main.xml and afterwards, build the design. You should choose the toolbox, if you want some options (ViewAnimator, button) and use the drag and drop method.

ViewAnimator

Here, you will see Graphical User Interface page

ViewAnimator

Step 6

Now, you will click the MainActivity.java page and you will build Java code.

First of all, you will declare the Header file (Extension file). 

ViewAnimator

Here, you will build the full Java code in MainActivity.java.

  1. package xyz.rvconstructions.www.viewanimatorapp;  
  2. import android.support.v7.app.AppCompatActivity;  
  3. import android.os.Bundle;  
  4. import android.view.View;  
  5. import android.view.animation.Animation;  
  6. import android.view.animation.AnimationUtils;  
  7. import android.widget.Button;  
  8. import android.widget.ImageView;  
  9. import android.widget.TextView;  
  10. import android.widget.ViewAnimator;  
  11. public class MainActivity extends AppCompatActivity {  
  12.     private ViewAnimator firstViewAnimator;  
  13.     Button btnNext;  
  14.     int[] images = {  
  15.         R.drawable.imgfirst,  
  16.         R.drawable.imgsecond,  
  17.         R.drawable.imgthird  
  18.     };  
  19.     @Override  
  20.     protected void onCreate(Bundle savedInstanceState) {  
  21.         super.onCreate(savedInstanceState);  
  22.         setContentView(R.layout.activity_main);  
  23.         btnNext = (Button) findViewById(R.id.buttonNext);  
  24.         firstViewAnimator = (ViewAnimator) findViewById(R.id.simpleViewAnimator);  
  25.         for (int i = 0; i < images.length; i++) {  
  26.             ImageView imageView = new ImageView(getApplicationContext());  
  27.             imageView.setImageResource(images[i]);  
  28.             firstViewAnimator.addView(imageView);  
  29.         }  
  30.         Animation in = AnimationUtils.loadAnimation(this, android.R.anim.slide_in_left);  
  31.         Animation out = AnimationUtils.loadAnimation(this, android.R.anim.slide_out_right);  
  32.         firstViewAnimator.setInAnimation( in );  
  33.         firstViewAnimator.setOutAnimation(out);  
  34.         firstViewAnimator.setAnimateFirstView(false);  
  35.         btnNext.setOnClickListener(new View.OnClickListener() {  
  36.             public void onClick(View v) {  
  37.                 firstViewAnimator.showNext();  
  38.             }  
  39.         });  
  40.     }  
  41. }  
Step 7

Now, you will see XML code, which is like activity_main.xml.
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="xyz.rvconstructions.www.viewanimatorapp.MainActivity">  
  3.     <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="25sp" android:textColor="#ff6600" android:layout_marginTop="5dp" android:text="C# corner" />  
  4.     <ViewAnimator android:id="@+id/simpleViewAnimator" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="50dp"> </ViewAnimator>  
  5.     <Button android:id="@+id/buttonNext" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginTop="200dp" android:background="#055" android:text="NEXT" android:textColor="#fff" android:textStyle="bold" /> </RelativeLayout>// This is just a sample script. Paste your real code (javascript or HTML) here. if ('this_is'==/an_example/){of_beautifier();}else{var a=b?(c%d):e[f];}  
Step 8

Now, you will go to run and select Run'app'.

ViewAnimator

Here, you will choose emulators and devices. Afterwards, you will click OK button.

ViewAnimator

Step 9

Now, you will see the output.

ViewAnimator

Now, you will click the next button and ViewAnimator changes.

ViewAnimator

ViewAnimator  
Ebook Download
View all
Learn
View all