Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to implement animation on custom view in android?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 443
    Comment on it

    In this tutorial, we will know that how to implement animation on our custom view in android through a simple example using a Library AndroidViewAnimations. The Animation is a technique which can effect  to any still view. In this tutorial, we will create a simple form and then will use animation to see effect and movement. Use following steps to implement animation technique in your  project.

    Step1- Adding support library in the dependencies

    To compile this library, we will add app's dependencies file. Open project build.gradle file and add this library. It will compile library at run time.

    dependencies {
         compile 'com.nineoldandroids:library:2.4.0'
         compile 'com.daimajia.easing:library:1.0.1@aar'
         compile 'com.daimajia.androidanimations:library:1.1.3@aar'
         compile 'com.android.support:recyclerview-v7:23.1.1'
    }

    Step2- Implementation of Animation on any custom view

    We will use with(), duration() and  playOn method. These method used to make animation on your view.

    YoYo.with(Techniques.Tada) // Tada is a Animation type.
        .duration(700)
        .playOn(Your view);

    Step3- Creating a layout

    Next, we will create a form view. So we have one EditText and one Button view in this layout. On button click, we will perform animation effect.

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:padding="@dimen/activity_horizontal_margin"
        android:layout_height="match_parent">
     
        <LinearLayout
            android:padding="@dimen/activity_horizontal_margin"
            android:id="@+id/edit_area"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
     
            <EditText
                android:hint="Username"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
     
            <EditText
                android:hint="Password"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
        </LinearLayout>
     
        <LinearLayout
            android:padding="@dimen/activity_horizontal_margin"
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
     
            <Button
                android:id="@+id/submit"
                android:text="Submit"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
        </LinearLayout>
     
    </LinearLayout>

     

    Step4- Implement animation on form view

    By click on submit button, we perform animation technique on our custom view.

    public class MainActivity extends Activity {
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
             
            // this is click listener method. It call when use click on the submit button
            findViewById(R.id.submit).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    
                    YoYo.with(Techniques.Tada)  // set the animation techniques
                            // set the time duration, with in animation to be performed
                            .duration(700)      
                            .playOn(findViewById(R.id.edit_area)); // set your view
     
                }
            });
        }
    }

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: