
When we are moving from one activity to other activity there we need to apply few effects those effects in android we applied as a animation.
For creating animation is very very simple just we create “anim” folder and in anim folder create one xml file write animation tags there for reference please check below program.
This is the xml main in anim folder
1 2 3 4 5 6 7 8 9 10 |
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false" > <translate android:duration="5000" android:fromXDelta="0%" android:toXDelta="-100%"/> <alpha android:duration="5000" android:fromAlpha="1.0" android:toAlpha="0.0" /> </set> |
this is another the xml main in anim folder
1 2 3 4 5 6 7 8 9 |
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromYDelta="-100%p" android:toYDelta="0" android:duration="5000"/> <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="5000" /> </set> |
MainActivity.java
Here am applying animation when am moving to second activity.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
package com.example.aniim; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void clock(View v){ Intent in=new Intent(getApplicationContext(),Second.class); startActivity(in); overridePendingTransition(R.anim.right, R.anim.lift); } } |
activity_main.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<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" tools:context="${relativePackage}.${activityClass}" > <Button android:id="@+id/button1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_below="@+id/textView1" android:text="Button" android:onClick="clock"/> </RelativeLayout> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
package com.example.aniim; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; public class Second extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_second); } } |
1 2 3 4 5 6 7 8 9 10 11 12 |
<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" tools:context="${relativePackage}.${activityClass}" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /> </RelativeLayout> |
Manifest.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.aniim" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="21" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".Second" android:label="@string/title_activity_second" > </activity> </application> </manifest> |