Lesson 3: Starting a New Project and Understanding XML Layout
INTRODUCTION
In this lesson you will be testing what each piece of code does, and how it works. You'll be changing certain parts of the code to see how it comes out in the 'Graphic Layout' of Eclipse.
LESSON OBJECTIVES
By the end of this lesson, you will be able to:
1. Learning how to 'Clean' your project
2. Understand TextView and Button code
3. Seeing what each piece of code actually does
LEARNING SEQUENCE
|
Required Reading
|
Read the following:
Introduction To Development Environment
· Eclipse
· Android
· Considerations for beginning programming.
|
Resources
|
View the following:
1. Eclipse
2. Android Development
|
Assignments
|
During this video, we’ll be showing you what each piece of code does in the ‘activity_main.xml’ and how to clean your project
First we’ll start with how to clean the project. Cleaning your project is when Eclipse scans your app of any false errors, and cleans it.
When you open your app, or you are sure you don't have any errors in the code, you should clean the app.
Go to PROJECT>CLEAN. Then the Clean menu will pop up. You can either clean all of your projects, or chose to clean only one of the projects. Cleaning all of them takes longer, so check the ‘Clean selected projects below’ and click only your project. This scans the whole app and gets rid of the errors that don’t actually exist, and leaves you with only the true errors
The rest of the errors you can change by checking the coding with the video, and hovering your mouse over the error and seeing what Eclipse suggests to fix it.
Next you will change what each piece of code does. Let’s start with ‘orientation’. This determines if it goes vertical or horizontal. Change the word vertical to horizontal, and open up the ‘graphic layout’ at the bottom left of the XML document.
You’ll now see that the app Layout hasn't changed, but the TextView and the Buttons have shifted to a horizontal view
Now the 'android:layout_width/height' coding. This piece of code determines how much space each piece of code takes up, as described in the last lesson
Changing the code here, you will not see a physical change except that the TextView and Buttons will shift around slightly in the graphic layout
The 'android:text' describes what the TextView and Button say on them. the 'android:textSize' will change how big the text will be.
- You can change the 'android:textSize' from dp to xp or sp. Which are all different text sizes.
- xp being the default for most devices, and will keep the text at a permanent size not matter the screen size. sp is another ratio, much like dp
- Changing the 'android:layout_gravity' will move around the pieces of the app. You can change it from 'center', to the 'right', and to the 'left'
- 'android:id' will not give you anything special in your app, changing this will not be shown in the graphic layout of Eclipse. The id refers to the identification of the app in the java.
|