Steps:
1. Create new project.
2. Now insert below code in SplashActivity
/********************************************* SplashScreen.java ***********************************************/
public class SplashScreen extends Activity {
private long ms = 0;
private long splashDuration = 5000;
private boolean splashActive = true;
private boolean paused = false;
private long splashDuration = 5000;
private boolean splashActive = true;
private boolean paused = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
AnimateScreen();
}
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
AnimateScreen();
}
private void AnimateScreen() {
// TODO Auto-generated method stub
Animation anim = AnimationUtils.loadAnimation(SplashScreen.this, R.anim.alpha);
anim.reset();
RelativeLayout l=(RelativeLayout) findViewById(R.id.RelativeLayout1);
l.clearAnimation();
l.startAnimation(anim);
// TODO Auto-generated method stub
Animation anim = AnimationUtils.loadAnimation(SplashScreen.this, R.anim.alpha);
anim.reset();
RelativeLayout l=(RelativeLayout) findViewById(R.id.RelativeLayout1);
l.clearAnimation();
l.startAnimation(anim);
anim = AnimationUtils.loadAnimation(SplashScreen.this, R.anim.translate);
anim.reset();
TextView life = (TextView) findViewById(R.id.textView1);
life.clearAnimation();
life.startAnimation(anim);
anim.reset();
TextView life = (TextView) findViewById(R.id.textView1);
life.clearAnimation();
life.startAnimation(anim);
anim = AnimationUtils.loadAnimation(SplashScreen.this, R.anim.translate);
TextView is = (TextView) findViewById(R.id.textView2);
is.clearAnimation();
is.startAnimation(anim);
TextView is = (TextView) findViewById(R.id.textView2);
is.clearAnimation();
is.startAnimation(anim);
anim = AnimationUtils.loadAnimation(SplashScreen.this, R.anim.translate);
TextView music = (TextView) findViewById(R.id.textView3);
music.clearAnimation();
music.startAnimation(anim);
TextView music = (TextView) findViewById(R.id.textView3);
music.clearAnimation();
music.startAnimation(anim);
Thread mythread = new Thread() {
public void run() {
try {
while (splashActive && ms < splashDuration) {
if (!paused)
ms = ms + 100;
sleep(100);
}
} catch (Exception e) {
} finally {
Intent intent = new Intent(SplashScreen.this, MainScreen.class);
startActivity(intent);
finish();
}
}
};
mythread.start();
}
public void run() {
try {
while (splashActive && ms < splashDuration) {
if (!paused)
ms = ms + 100;
sleep(100);
}
} catch (Exception e) {
} finally {
Intent intent = new Intent(SplashScreen.this, MainScreen.class);
startActivity(intent);
finish();
}
}
};
mythread.start();
}
}
/******************************************************************** ******************************************/
3. Now insert below code in xml file.
/************************************************* SplashScreen .xml ******************************************/
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:keepScreenOn="true"
tools:context=".SplashScreen" >
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:keepScreenOn="true"
tools:context=".SplashScreen" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:textSize="20sp"
android:textColor="#ffffff"
android:textStyle="bold|italic"
android:text="@string/Life">
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:textSize="20sp"
android:textColor="#ffffff"
android:textStyle="bold|italic"
android:text="@string/Life">
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView2"
android:layout_marginTop="24dp"
android:textSize="20sp"
android:textStyle="bold|italic"
android:textColor="#ffffff"
android:text="@string/Music" />
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView2"
android:layout_marginTop="24dp"
android:textSize="20sp"
android:textStyle="bold|italic"
android:textColor="#ffffff"
android:text="@string/Music" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView3"
android:layout_below="@+id/textView1"
android:layout_marginTop="26dp"
android:textSize="20sp"
android:textStyle="bold|italic"
android:textColor="#ffffff"
android:text="@string/Is" />
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView3"
android:layout_below="@+id/textView1"
android:layout_marginTop="26dp"
android:textSize="20sp"
android:textStyle="bold|italic"
android:textColor="#ffffff"
android:text="@string/Is" />
</RelativeLayout>
/**************************************************************************************************************/
4. To create animation with screen and textview create two xml files and insert code.
/************************************************* translate .xml ******************************************/
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android">
<set
xmlns:android="http://schemas.android.com/apk/res/android">
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="0%"
android:toXDelta="0%"
android:fromYDelta="200%"
android:toYDelta="0%"
android:duration="2000"
android:zAdjustment="top" />
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="0%"
android:toXDelta="0%"
android:fromYDelta="200%"
android:toYDelta="0%"
android:duration="2000"
android:zAdjustment="top" />
</set>
/**************************************************************************************************************/
/************************************************* alpha .xml ******************************************/
<?xml version="1.0" encoding="utf-8"?>
<alpha
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="3000" />
<alpha
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="3000" />
/**************************************************************************************************************/
5. To see animation of layout you use in main file insert background image or color to Splashscreen layout.
6. Now create new activity an give name MainScreen .
When animation completed
Intent intent = new Intent(SplashScreen.this, MainScreen.class);
startActivity(intent);
startActivity(intent);
finish();
Above code handle your activity life cycle.
Here is the sample: code
Comments
Post a Comment