Animation in android app (Zoom/Slide up/Clocking)

Hello friends
today we are going to learn about an animation in android. into this example we are going to take a three animation method.
it's basic animation method. 1. zoom 2.clock 3. side

zoom : using this animation we can zoom any object in android.
clock : using this animation we can clock wise run object in android.
slide : using this we can slide up any object in android.

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/relativeLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/android"
    tools:context=".MainActivity">

    <Button
        android:id="@+id/zoom"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginTop="40dp"
        android:onClick="zoom"
        android:text="zoom" />
    <Button
        android:id="@+id/clock"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/zoom"
        android:layout_centerHorizontal="true"
        android:onClick="clock"
        android:text="clock" />
    <Button
        android:id="@+id/slide"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_marginTop="40dp"
        android:onClick="slide"
        android:text="slide" />
</RelativeLayout>

MainActivity.java


public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
    public void slide(View view) {
        RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.relativeLayout);
        Animation animation =
                AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide);
        relativeLayout.startAnimation(animation);
    }
    public void clock(View view) {
        RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.relativeLayout);
        Animation animation = AnimationUtils.loadAnimation(getApplicationContext(),
                R.anim.clocking);
        relativeLayout.startAnimation(animation);
    }
    public void zoom(View view) {
        RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.relativeLayout);
        Animation animation = AnimationUtils.loadAnimation(getApplicationContext(),
                R.anim.zoom);
        relativeLayout.startAnimation(animation);
    }
}

clocking.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <rotate xmlns:android="http://schemas.android.com/apk/res/android"
        android:fromDegrees="0"
        android:toDegrees="320"
        android:pivotX="50%"
        android:pivotY="50%"
        android:duration="6000" >
    </rotate>

    <rotate xmlns:android="http://schemas.android.com/apk/res/android"
        android:startOffset="5000"
        android:fromDegrees="320"
        android:toDegrees="0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:duration="6000" >
    </rotate>
</set>

zoom.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <scale xmlns:android="http://schemas.android.com/apk/res/android"
        android:fromXScale="0.5"
        android:toXScale="3.0"
        android:fromYScale="0.5"
        android:toYScale="3.0"
        android:duration="6000"
        android:pivotX="50%"
        android:pivotY="50%" >
    </scale>
    <scale xmlns:android="http://schemas.android.com/apk/res/android"
        android:startOffset="5000"
        android:fromXScale="3.0"
        android:toXScale="0.5"
        android:fromYScale="3.0"
        android:toYScale="0.5"
        android:duration="6000"
        android:pivotX="50%"
        android:pivotY="50%" >
    </scale>
</set>

slide.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <scale
        android:duration="500"
        android:fromXScale="1.0"
        android:fromYScale="1.0"
        android:interpolator="@android:anim/linear_interpolator"
        android:toXScale="1.0"
        android:toYScale="0.0" />
</set>

OUTPUT:





Comments