You are on page 1of 24

Flower App

Problem
Solution
1. Create new project
2. Prepare data for the app
3. Redefine the main layout
1. Create new project
• Open Android Studio
• New Project…
• Application name: Flower
• Company domain: eiu.edu.vn
• Click Edit on the right of Package name:
• Package name: vn.edu.eiu.android.flower > Next

• Check Phone and Tablet (uncheck the others) > Next

• Empty Activity > Next

• Activity Name: MainActivity > Finish


1. Create new project
1. Create new project
1. Create new project
1. Create new project
1. Create new project
1. Create new project
1. Create new project
1. Create new project
2. Prepare data for the app
• Define 2 strings in res/values/strings.xml

<string name="name">Tibouchina Semidecandra</string>

<string name="instructions">Beautiful large royal purple flowers adorn


attractive satiny green leaves that turn orange/red in cold weather. Grows to up
to 18 feet, or prune annually to shorten.</string>

• Copy princess_flower.png to res/drawable_xhdpi > OK


2. Prepare data for the app
3. Redefine the main layout
• activity_main.xml (res/layout)
• In Text view
• Change RelativeLayout to LinearLayout
• Add android:layout_margin="@dimen/activity_horizontal_margin"
• Delete the TextView component
• In Design view > Properties
• orientation: vertical
3. Redefine the main layout
• Add visual components to the layout
• In Design view, drag in a TextView to the top center
• id: nameTextView
• text: @string/name
• Drag in an ImageView below the TextView
• src: @drawable/princess_flower
• Drag in a Plain TextView below the ImageView
• id: instructionsTextView
• text: @string/instructions
• Run the project
• Click the Run button
• Select the Emulator Nexus_5 > OK
• Set the margins using dp (device-independent pixels)
• (On 160dpi screen, each dp is mapped to a physical pixel)
• For the Large Text and the ImageView, add
android:layout_marginBottom="10dp"
• Run the project
• Define a text style
• res/values/styles.xml (sp: scale-independent pixels. Similar to dp but used to
specify font sizes)
• res/layout/activity_main.xml
• Run the project

You might also like