Introduction
In this first, you will create two XML files inside the anim folder that defines the animation to be performed on the button click.
anim1
- <?xml version="1.0" encoding="utf-8"?>
- <translate xmlns:android="http://schemas.android.com/apk/res/android"
- android:fromXDelta="100%p"
- android:toXDelta="0"
- android:duration="500"/>
anim2
- <?xml version="1.0" encoding="utf-8"?>
- <translate xmlns:android="http://schemas.android.com/apk/res/android"
- android:fromXDelta="0"
- android:toXDelta="-50%p"
- android:duration="500"/>
- Activityoptions
a helper class to build an option bundle to be used with "context.startActivity(Intent,Bundle)" and related methods. - makeCustomAnimation
Create an "ActivityOptions" specifying a custom animation to run when the Activity is displayed. It returns an Activity Options type object that we to the "startActivity()" to perform the sliding operation.
- <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:paddingLeft="@dimen/activity_horizontal_margin"
- android:paddingRight="@dimen/activity_horizontal_margin"
- android:paddingTop="@dimen/activity_vertical_margin"
- android:paddingBottom="@dimen/activity_vertical_margin"
- tools:context=".MainActivity"
- >
- <Button
- android:id="@+id/button"
- android:layout_height="wrap_content"
- android:layout_width="300dp"
- android:text="Slide"
- android:textStyle="italic"
- android:textSize="40dp"
- android:layout_centerHorizontal="true"
- ></Button>
- </RelativeLayout>
Step 2
Create another XML file and write this:
- <?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:layout_height="match_parent"
- android:background="#234567">
- <ImageView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:src="@drawable/download"
- android:layout_gravity="center"
- android:layout_marginTop="100dp"
- ></ImageView>
- </LinearLayout>


Join the conversation! Your thoughts help the community grow.