Sunday 23 September 2012

android: Splash screen


Splash.java

public class Splash extends Activity {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.splashscreen,
(ViewGroup) findViewById(R.id.splash));
Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();


new Handler().post(new Runnable() {
@Override
public void run() {
Splash.this.startActivity(new Intent(Splash.this,
MainActivity.class));
Splash.this.finish();
}
});


}
}

splashscreen.xml 


<?xml version="1.0" encoding="utf-8"?>
<FrameLayout android:id="@+id/splash"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<ImageView android:id="@+id/splashscreen"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:src="@drawable/splashbig" android:scaleType="fitXY"
android:layout_gravity="center" />
</FrameLayout>

No comments:

Post a Comment