Android Comes with pretty cool animation, today I am going to discuss how to do fade in and fade out transition between the pages.
Step 1 :- Create anim folder under res folder
Step 2:- In anim folder create two xml file,
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator"
android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="2000" />
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator"
android:fromAlpha="1.0" android:toAlpha="0.0" android:
duration="2000" />
Step 3:- Create two xml file under layout folder
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Next" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textSize="25sp"
android:layout_marginTop="42dp"
android:text="@string/hello_world" />
</RelativeLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Second Activity"
android:textSize="25sp" />
</LinearLayout>
Step 4:- Create MainActivity.java file
package com.arpit.activitypagetransition;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
Button btnNext;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
overridePendingTransition(R.anim.fadein, R.anim.fadeout);
setContentView(R.layout.first);
System.out.println("----main activity---onCreate---");
btnNext = (Button) findViewById(R.id.button1);
btnNext.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent ob = new Intent(MainActivity.this, Second.class);
startActivity(ob);
}
});
}
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
System.out.println("----main activity---onStart---");
overridePendingTransition(R.anim.fadein, R.anim.fadeout);
}
}
Step 5:- create Second.java file
package com.arpit.activitypagetransition;
import android.app.Activity;
import android.os.Bundle;
public class Second extends Activity {
protected void onCreate(Bundle savedInstance){
super.onCreate(savedInstance);
overridePendingTransition(R.anim.fadein, R.anim.fadeout);
setContentView(R.layout.second);
System.out.println("----Secondactivity activity---onCreates---");
}
}
Step 6:- AndroidManifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.arpit.activitypagetransition"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.arpit.activitypagetransition.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"></activity>
</application>
</manifest>
Catch Me On: CreateAppFaster.com
Step 1 :- Create anim folder under res folder
Step 2:- In anim folder create two xml file,
- fadein.xml
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator"
android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="2000" />
- fadeout.xml
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator"
android:fromAlpha="1.0" android:toAlpha="0.0" android:
duration="2000" />
Step 3:- Create two xml file under layout folder
- first.xml
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Next" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textSize="25sp"
android:layout_marginTop="42dp"
android:text="@string/hello_world" />
</RelativeLayout>
- second.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Second Activity"
android:textSize="25sp" />
</LinearLayout>
Step 4:- Create MainActivity.java file
package com.arpit.activitypagetransition;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
Button btnNext;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
overridePendingTransition(R.anim.fadein, R.anim.fadeout);
setContentView(R.layout.first);
System.out.println("----main activity---onCreate---");
btnNext = (Button) findViewById(R.id.button1);
btnNext.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent ob = new Intent(MainActivity.this, Second.class);
startActivity(ob);
}
});
}
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
System.out.println("----main activity---onStart---");
overridePendingTransition(R.anim.fadein, R.anim.fadeout);
}
}
Step 5:- create Second.java file
package com.arpit.activitypagetransition;
import android.app.Activity;
import android.os.Bundle;
public class Second extends Activity {
protected void onCreate(Bundle savedInstance){
super.onCreate(savedInstance);
overridePendingTransition(R.anim.fadein, R.anim.fadeout);
setContentView(R.layout.second);
System.out.println("----Secondactivity activity---onCreates---");
}
}
Step 6:- AndroidManifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.arpit.activitypagetransition"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.arpit.activitypagetransition.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"></activity>
</application>
</manifest>
Technorati Tags: android fade in fade out transition,android fade in fade out animation,page transition android
Catch Me On: CreateAppFaster.com
0 comments:
Post a Comment