1 page.title=Tng quan v Ti nguyn 2 @jd:body 3 4 <div id="qv-wrapper"> 5 <div id="qv"> 6 <h2>Ch </h2> 7 <ol> 8 <li><a href="providing-resources.html">Cung cp Ti nguyn</a></li> 9 <li><a href="accessing-resources.html">Truy cp Ti nguyn</a></li> 10 <li><a href="runtime-changes.html">X l Thay i Thi gian chy</a></li> 11 <li><a href="localization.html">Bn a ha</a></li> 12 </ol> 13 14 <h2>Tham kho</h2> 15 <ol> 16 <li><a href="available-resources.html">Loi Ti nguyn</a></li> 17 </ol> 18 </div> 19 </div> 20 21 22 <p>Bn nn lun ngoi hin ha cc ti nguyn chng hn nh hnh nh v xu t m 23 ng dng ca mnh, sao cho bn c th duy tr chng mt cch c lp. Vic ngoi hin ha 24 ti nguyn cng cho php bn cung cp cc ti nguyn thay th h tr nhng cu hnh 25 thit b c th chng hn nh ngn ng hoc kch c mn hnh khc nhau, iu ny ang ngy cng tr nn 26 quan trng bi cc thit b da trn nn tng Android ngy cng sn c vi cc cu hnh khc nhau. 27 m bo tnh tng thch vi cc cu hnh khc nhau, bn phi t chc ti nguyn trong 28 th mc {@code res/} d n ca bn bng cch s dng cc th mc con khc nhau c chc nng nhm ti nguyn li theo loi v 29 cu hnh.</p> 30 31 <div class="figure" style="width:429px"> 32 <img src="{@docRoot}images/resources/resource_devices_diagram1.png" height="167" alt="" /> 33 <p class="img-caption"> 34 <strong>Hnh 1.</strong> Hai thit b khc nhau, mi thit b s dng b tr mc nh 35 (ng dng khng cung cp b tr thay th).</p> 36 </div> 37 38 <div class="figure" style="width:429px"> 39 <img src="{@docRoot}images/resources/resource_devices_diagram2.png" height="167" alt="" /> 40 <p class="img-caption"> 41 <strong>Hnh 2.</strong> Hai thit b khc nhau, mi thit b s dng mt b tr khc nhau c cung cp 42 cho cc kch c mn hnh khc nhau.</p> 43 </div> 44 45 <p>i vi mi loi ti nguyn, bn c th quy nh ti nguyn <em>mc nh</em> v nhiu ti nguyn 46 <em>thay th</em> cho ng dng ca mnh:</p> 47 <ul> 48 <li>Ti nguyn mc nh l nhng ti nguyn nn c s dng khng ph thuc vo 49 cu hnh thit b hoc khi khng c ti nguyn thay th khp vi cu hnh 50 hin ti.</li> 51 <li>Ti nguyn thay th l nhng ti nguyn m bn thit k s dng vi mt cu hnh 52 c th. quy nh rng mt nhm ti nguyn p dng cho mt cu hnh c th, 53 hy ni hnh dng cu hnh ph hp vi tn th mc.</li> 54 </ul> 55 56 <p>V d, trong khi b tr UI mc nh ca bn 57 c lu trong th mc {@code res/layout/}, bn c th quy nh mt b tr khc s 58 c s dng khi mn hnh hng kh ngang, bng cch lu n trong th mc {@code res/layout-land/} 59 . Android t ng p dng cc ti nguyn ph hp bng cch khp cu hnh hin ti 60 ca thit b vi tn th mc ti nguyn ca bn.</p> 61 62 <p>Hnh 1 minh ha cch h thng p dng cng b tr cho 63 hai thit b khc nhau khi khng c sn ti nguyn thay th. Hnh 2 minh ha 64 cng ng dng khi n thm mt ti nguyn b tr thay th cho cc mn hnh ln hn.</p> 65 66 <p>Cc ti liu sau trnh by hng dn hon chnh v cch bn c th t chc cc ti nguyn ng dng ca mnh, 67 quy nh ti nguyn thay th, truy cp chng trong ng dng ca bn, v nhiu iu khc:</p> 68 69 <dl> 70 <dt><strong><a href="providing-resources.html">Cung cp Ti nguyn</a></strong></dt> 71 <dd>Nhng kiu ti nguyn m bn c th cung cp trong ng dng ca mnh, ni lu chng, v cch to 72 ti nguyn thay th cho nhng cu hnh thit b c th.</dd> 73 <dt><strong><a href="accessing-resources.html">Truy cp Ti nguyn</a></strong></dt> 74 <dd>Cch s dng ti nguyn m bn cung cp hoc bng cch tham chiu chng t m ng dng ca mnh 75 hoc t cc ti nguyn XML khc.</dd> 76 <dt><strong><a href="runtime-changes.html">X l Thay i Thi gian chy</a></strong></dt> 77 <dd>Cch qun l nhng thay i cu hnh m din ra trong khi Hot ng ca bn ang chy.</dd> 78 <dt><strong><a href="localization.html">Bn a ha</a></strong></dt> 79 <dd>Mt hng dn t di ln v vic bn a ha ng dng ca bn bng cch s dng cc ti nguyn thay th. Trong khi y 80 ch l mt cng dng c th ca ti nguyn thay th, n rt quan trng tip cn vi nhiu 81 ngi dng hn.</dd> 82 <dt><strong><a href="available-resources.html">Loi Ti nguyn</a></strong></dt> 83 <dd>Mt tham chiu v cc loi ti nguyn khc nhau m bn c th cung cp, m t cc phn t XML, 84 thuc tnh v c php ca chng. V d, tham chiu ny cho bn thy cch to mt ti nguyn cho 85 menu ng dng, i tng v c, hot nh, v hn th na.</dd> 86 </dl> 87 88 <!-- 89 <h2>Raw Assets</h2> 90 91 <p>An alternative to saving files in {@code res/} is to save files in the {@code 92 assets/} directory. This should only be necessary if you need direct access to original files and 93 directories by name. Files saved in the {@code assets/} directory will not be given a resource 94 ID, so you can't reference them through the {@code R} class or from XML resources. Instead, you can 95 query data in the {@code assets/} directory like an ordinary file system, search through the 96 directory and 97 read raw data using {@link android.content.res.AssetManager}. For example, this can be more useful 98 when dealing with textures for a game. However, if you only need to read raw data from a file 99 (such as a video or audio file), then you should save files into the {@code res/raw/} directory and 100 then read a stream of bytes using {@link android.content.res.Resources#openRawResource(int)}. This 101 is uncommon, but if you need direct access to original files in {@code assets/}, refer to the {@link 102 android.content.res.AssetManager} documentation.</p> 103 --> 104