Download as pdf or txt
Download as pdf or txt
You are on page 1of 20

MY NUMBER GUESSING GAME

OBJECTIVES

1. Transition Between Activities


2. Data Transfer Between Activities
3. Creating Splash Screen
4. Creating Animation

CREATE NEW ACTIVITY

1. In the Project window, right click in the com.example.mynumberguessinggame folder, select


New -> Activity -> Empty Activity.

2. The New Android


Activity dialog box
will display. Type
the name of activity
as “SplashActivity”
then click the
“Finish” button.
3. The SplashActivity will then be added in the com.example.mynumberguessinggame folder.

LAYOUT – SPLASH
ATTRIBUTES

COMPONENT ATTRIBUTE VALUE


ConstraintLayout
ImageView id imageView
Layout_width 350dp
Layout_height 350dp

TO CENTER THE IMAGEVIEW HORIZONTALLY

1. Right-click on the image


2. Select Center -> Horizontally
When you use ConstraintsLayout, you need set a constraints on the component. To set a constraints
in the ImageView.

1. In the Attributes window, click the plus button to create top, bottom, left or right
constraints.

2. Set only the top and bottom constraints. You could use any value. Your screen should be
display below.
TextView id textView
layout_width 300dp
layout_height Wrap_content
text Number Guessing Game
textColor #F60303

TO SET THE TEXTALIGNMENT ATTRIBUTE

1. Click the code tab

2. Type the following code in the TextView tag.

android:textAlignment = “center”
TO CENTER THE TEXTVIEW HORIZONTALLY

1. Right-click on the TextView


2. Select Center -> Horizontally

When you use ConstraintsLayout, you need set a constraints on the component. To set a constraints
in the ImageView.

1. In the Attributes window, click the plus button to


create top, bottom, left or right constraints.
2. Set only the top and bottom constraints. You could use any value. Your screen should be
display below.

CREATE ANIMATION FOLDER

1. In the Project window, right-click in res folder. Click New -> Android Resource Directory.
2. The “New Resource Directory” will display. Select the “anim” folder then click the OK
button.

3. The “anim” folder will then be created inside the “res” folder as shown.
CREATE ANIMATION RESOURCE FILE

1. Right-click in the “anim” folder, Select New -> Animation Resource File.

2. The “New Resource File” dialog box will then display. Type “image_animation” as the file
name then click the “OK” button.
3. The image_animation.xml will then be created.

4. Right-click in the “anim” folder, Select New -> Animation Resource File.
5. The “New Resource File” dialog box will then display. Type “text_animation” as the file name
then click the “OK” button.

6. The text_animation.xml will then be created.


WRITE THE CODE FOR THE ANIMATION

1. Click the image_animation.xml tab.

2. Type the following code.

3. Click the text_animation.xml tab.


4. Type the following code.

WRITE CODE – SPLASHACTIVITY.JAVA

1. Type the following code in SplashActivity.java

2. Implement the methods for the CountDownTimer method. Click on the line “new
CountDownTimer” and click the light bulb icon.
3. Select “Implement methods” from the options.

4. The “Select Methods to Implement” dialog box will then display. The two methods is
already selected. Click the “OK” button.
5. The two methods will then be created.

6. Type the following code inside the “onFinish” method.

7. To remove the error on the onFinish method, click on the line. Right click, select “Show
Context Actions”.
8. Select “Import Class”

The package will be imported and the error will then be removed.

9. Type the remaining code.


SET THE ANDROIDMANIFEST.XML

1. Click the Project window, Select “manifest” folder then “AndroidManifest.xml”

2. Highlight the following code and press Ctrl + X or right-click then select the “Cut” command.
3. Paste it after the

<activity
android:name = “SplashActivty”
android:exported = true
4. Remove the slash in the first activity tag.
5. Put the closing tag for the activity.

6. Change the “exported” to “true”.

You might also like