---
Developing MyQuiz Android Apps Part 2
Developing MyQuiz Apps Part 2
Using ADT 18 On Win 7
CREATING SPLASH SCREEN DELAY EFFECT
0) Continue from previous tutorial
or download startup file
1) Copy logo image into drawable folder
1.1) Save the following image as logo.png in the drawable folder.
2) Insert ImageView object in the splash layout file.
Replace the content of splash layout file as follows.
<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:background="@drawable/bckgrnd">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/logo" />
</RelativeLayout>
|
File name: MyQuiz/res/layout/splash.xml
You can simulate the landscape view by clicking the orientation button.
|
3) Edit QuizSplashActivity.java
package com.example.myquiz;
import android.os.Bundle;
public class QuizSplashActivity extends QuizActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// This method will be executed once the timer is over
// Start QuizMenuActivity
Intent i = new Intent(QuizSplashActivity.this, QuizMenuActivity.class);
startActivity(i);
// close this activity
finish();
}
}, 3000); //3000 milliseconds
}
}
|
You have to import the following classes…
import android.content.Intent;
import android.os.Handler;
|
Read more about handler and postDelayed here,http://developer.android.com/reference/android/os/Handler.html#postDelayed(java.lang.Runnable, long)
|
4) Check Android Manifest
Make sure that the activity QuizMenuActivity is added into Android Manifest.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myquiz"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.myquiz.QuizSplashActivity"
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="QuizMenuActivity">
</activity>
</application>
</manifest>
|
No comments:
Post a Comment