You are on page 1of 5

B2: i ti res/main.xml xy dng giao din cho chng trnh: M: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.

.com/apk/res/andro id" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <EditText android:id="@+id/work_enter" android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="@string/work_hint" android:lines="1" android:textSize="24px" /> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:layout_width="50px" android:layout_height="wrap_content" android:text="@string/hour_edit" android:typeface="normal" android:textSize="15px" android:textStyle="bold"

android:padding="5px" /> <EditText android:id="@+id/hour_edit" android:layout_width="45px" android:layout_height="wrap_content" android:hint="12" android:textColorHint="@color/hint_color" android:textSize="20px" android:gravity="center" android:padding="5px" android:numeric="integer" android:maxLength="2" /> <TextView android:layout_width="65px" android:layout_height="wrap_content" android:text="@string/minute_edit" android:typeface="normal" android:textSize="15px" android:textStyle="bold" android:padding="5px" /> <EditText android:id="@+id/minute_edit" android:layout_width="45px" android:layout_height="wrap_content" android:hint="00" android:textColorHint="@color/hint_color" android:textSize="20px" android:gravity="center" android:padding="5px" android:numeric="integer" android:maxLength="2" /> </LinearLayout> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content"

android:gravity="center" android:text="@string/button_content" /> <ListView android:id="@+id/list" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout>

Giao din ta thit k y c 1 Linear Layout lm thnh phn chnh, cc thnh phn con ca n gm 1 Edit Text (dng nhp ni dung cng vic), 1 Linear Layout (li gm cc thnh phn con nhp gi v pht thc hin cng vic), 1 Button ( thm ni dung cng vic vo List View) v 1 List View dng list cc cng vic bn nhp. T kha lines c dng c nh s dng v nn s dng vi Edit Text thay v dng mi wrap_content v nu sd wrap_content th Edit Text s t gin ra nu dng nhp vo vt gii hn ng bao (lm hng giao din bn thit k). T kha gravity thng bo cc thnh phn con s c sp xp ntn thnh phn cha. y mnh dng "center" ngha l thnh phn con nm trung tm. Hy th thm vo 1 Edit Text: M: android:gravity="center" Bn s thy dng ch nhp vo s bt u t gia ca Edit Text ch khng bt u t bn tri nh trc na. T kha padding dng cch 1 khong cch cho thnh phn. Nu khng c padding th 2 thnh phn con thuc cng 1 LinearLayout s c xp st nhau, nhng nu 1 thnh phn con s dng padding th s to c khong cch vi

thnh phn cn li theo mong mun. Ngoi ra cn c paddingLeft, paddingRight, paddingTop, paddingBottom. T kha numeric dng gii hn dng k t nhp vo. y mnh mun ch nhp vo ch s nn dng "integer" T kha maxLength dng gii hn s k t nhp vo. Do Edit Text ny dng nhp gi nn maxLength="2". Ok, gi n 1 cht kin thc v cc n v ca dimenson: - px (pixel): im chm trn mn hnh. - in (inch) - mm (milimet) - pt (point) = 1/72 m - dp (density - independent pixel): ci ny hi kh gii thch. Ni chung dp c s dng cho nhiu phn gii, v vi phn gii 160 px/inch th 1 dp = 1 px. - sp: gn ging dp, nn s dng cho text size. Ni chung nn s dng dp v sp nh ngha size cho cc thnh phn, v n c t l c nh vi phn gii ca mn hnh. Cn nu bn ch tm xy dng cho 1 phn gii nht nh th dng px cho chnh xc v chc chn. B3: Ti values/strings.xml chnh sa nh sau: M: <?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">Example 2</string> <string name="work_hint">Enter the work here</string> <string name="hour_edit">Hour</string> <string name="minute_edit">Minute</string> <string name="button_content">Add work</string> </resources> B4: To mi colors.xml trong values vi ni dung: M: <?xml version="1.0" encoding="utf-8"?>

<resources> <color name="hint_color">#cccccc</color> </resources>

OK, vy l hon thin phn giao din. Cc bn c th cho chy th ngay kim tra xem giao din nh mun cha ch khng cn i hon thnh c code (Run as -> Android Application).

You might also like