1 page.title=Tng quan v UI 2 @jd:body 3 4 5 <p>Tt c phn t giao din ngi dng trong mt ng dng Android u c xy dng bng cch s dng cc i tng {@link android.view.View} v 6 {@link android.view.ViewGroup}. {@link android.view.View} l mt i tng c chc nng v 7 th g trn mn hnh m ngi dng c th tng tc vi. {@link android.view.ViewGroup} l mt i tng 8 c chc nng gi cc i tng {@link android.view.View} (v {@link android.view.ViewGroup}) khc 9 nh ngha b tr ca giao din.</p> 10 11 <p>Android cung cp mt b su tp c lp con {@link android.view.View} v {@link 12 android.view.ViewGroup} cung cp cho bn cc cch iu khin nhp liu thng dng (chng hn nh nt v 13 trng vn bn) v cc m hnh b tr khc nhau (chng hn nh b tr tuyn tnh hoc tng i).</p> 14 15 16 <h2 id="Layout">B tr Giao din Ngi dng</h2> 17 18 <p>Giao din ngi dng ca tng thnh phn trong ng dng ca bn c nh ngha bng cch s dng mt phn cp ca cc i tng {@link 19 android.view.View} v {@link android.view.ViewGroup} nh minh ha trong hnh 1. Mi nhm dng xem 20 l mt b cha v hnh c chc nng t chc cc dng xem con, trong khi dng xem con c th l 21 iu khin nhp liu hoc cc widget khc 22 v mt phn no ca UI. Cy phn cp ny c th n gin hoc phc tp nh nhu cu 23 ca bn (nhng n gin s tt cho hiu nng).</p> 24 25 <img src="{@docRoot}images/viewgroup.png" alt="" /> 26 <p class="img-caption"><strong>Hnh 1.</strong> Minh ha mt phn cp dng xem c chc nng nh ngha mt 27 b tr UI.</p> 28 29 <p> khai bo b tr ca mnh, bn c th khi to cc i tng {@link android.view.View} trong m v bt u 30 xy dng mt cy, nhng cch d nht v hiu qu nht nh ngha b tr ca bn l bng mt tp XML. 31 XML cung cp mt cu trc m ngi dng c th c c cho b tr, tng t nh HTML.</p> 32 33 <p>Tn ca phn t XML i vi mt dng xem tng ng vi lp Android m n biu din. V th mt phn t 34 <code><TextView></code> to ra mt widget {@link android.widget.TextView} trong UI ca bn, 35 v mt phn t <code><LinearLayout></code> to ra mt nhm dng xem {@link android.widget.LinearLayout} 36 . </p> 37 38 <p>V d, mt b tr thng ng n gin vi dng xem vn bn v nt trng nh sau:</p> 39 <pre> 40 <?xml version="1.0" encoding="utf-8"?> 41 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 42 android:layout_width="fill_parent" 43 android:layout_height="fill_parent" 44 android:orientation="vertical" > 45 <TextView android:id="@+id/text" 46 android:layout_width="wrap_content" 47 android:layout_height="wrap_content" 48 android:text="I am a TextView" /> 49 <Button android:id="@+id/button" 50 android:layout_width="wrap_content" 51 android:layout_height="wrap_content" 52 android:text="I am a Button" /> 53 </LinearLayout> 54 </pre> 55 56 <p>Khi bn ti mt ti nguyn b tr trong ng dng ca mnh, Android khi to tng nt ca b tr vo mt 57 i tng thi gian chy m bn c th s dng nh ngha cc hnh vi b sung, truy vn trng thi ca i tng hoc sa i 58 b tr.</p> 59 60 <p> xem hng dn y v to b tr UI, hy xem phn <a href="declaring-layout.html">B tr 61 XML</a>. 62 63 64 <h2 id="UIComponents">Thnh phn Giao din Ngi dng</h2> 65 66 <p>Bn khng phi xy dng tt c UI ca mnh bng cch s dng cc i tng {@link android.view.View} v {@link 67 android.view.ViewGroup}. Android cung cp mt vi thnh phn ng dng a ra mt 68 b tr UI chun m bn ch cn nh ngha ni dung cho n. Mi thnh phn UI nh vy 69 u c mt b API duy nht c m t trong cc ti liu tng ng, chng hn nh <a href="{@docRoot}guide/topics/ui/actionbar.html">Thanh Hnh ng</a>, <a href="{@docRoot}guide/topics/ui/dialogs.html">Hp thoi</a> v <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html">Thng bo Trng thi</a>.</p> 70 71 72