Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to create anticipate Image animation function in android

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 290
    Comment on it

    In the below example I have created anticipate Image animation function. Here I have added Button and ImageView in actvity_main.xml layout then I have created new directory (anim). In anim directory I have created anticipate.xml layout and In MainActivity I have used AnimationUtils.loadAnimation function setOnClickListener method. You can see below program it will clearly describe you to anticipate Image animation in android.

    Step(1)activity_main.xml-

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    
    
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="horizontal">
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:orientation="vertical"
                android:gravity="bottom"
                android:layout_margin="30dp">
                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/one"
                    android:id="@+id/image"
                    android:textColor="@color/colorAccent"
                    android:textStyle="italic"
                    android:textSize="25dp"/>
            </LinearLayout>
            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:orientation="vertical">
                <Button
                    android:id="@+id/anticipate"
                    android:layout_marginTop="40dp"
                    android:layout_width="200dp"
                    android:layout_height="wrap_content"
                    android:background="@color/colorAccent"
                    android:text="Click me"/>
                </LinearLayout>
            </LinearLayout>
        </LinearLayout>

    Step(2)-MainActivity-

     public class MainActivity extends AppCompatActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            final Animation animAnticipate = AnimationUtils.loadAnimation(this, R.anim.anticipate);
            final ImageView text = (ImageView) findViewById(R.id.image);
            Button btnBounce = (Button) findViewById(R.id.anticipate);
            btnBounce.setOnClickListener(new Button.OnClickListener() {
    
                @Override
                public void onClick(View arg0) {
                    text.startAnimation(animAnticipate);
    
                }
            });
        }
    
    }

    Step(3)-In anim directory I have created anticipate.xml layout-

     <?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android"
        android:interpolator="@android:anim/anticipate_overshoot_interpolator">
        <translate
            android:fromYDelta="-90%p"
            android:toYDelta="0"
            android:duration="2200"/>
    </set>

     

 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: