Home | History | Annotate | Download | only in material
      1 page.title=nh ngha Hot hnh Ty chnh
      2 
      3 @jd:body
      4 
      5 <div id="tb-wrapper">
      6 <div id="tb">
      7 <h2>Bi hc ny hng dn bn cch</h2>
      8 <ol>
      9   <li><a href="#Touch">Ty chnh Phn hi Chm</a></li>
     10   <li><a href="#Reveal">S dng Hiu ng L ra</a></li>
     11   <li><a href="#Transitions">Ty chnh Chuyn tip Hot ng</a></li>
     12   <li><a href="#ViewState">To Hiu ng Hot hnh Thay i Trng thi Xem</a></li>
     13   <li><a href="#AnimVector">To Hiu ng Hot hnh Ni dung v c Vc-t</a></li>
     14 </ol>
     15 <h2>Bn cng nn c</h2>
     16 <ul>
     17   <li><a href="http://www.google.com/design/spec">c t phong cch Material Design</a></li>
     18   <li><a href="{@docRoot}design/material/index.html">Material Design trn Android</a></li>
     19 </ul>
     20 </div>
     21 </div>
     22 
     23 
     24 <p>Hot hnh theo phong cch material design phn hi hnh ng ca ngi dng v cung cp
     25 tnh lin tc trc quan khi ngi dng tng tc vi ng dng ca bn. Giao din material cung cp mt s hot hnh
     26 mc nh cho cc nt v chuyn tip hot ng, v Android 5.0 (API mc 21) v cao hn cho php bn ty chnh
     27 nhng hot hnh ny v to cc hot hnh mi:</p>
     28 
     29 <ul>
     30 <li>Phn hi chm</li>
     31 <li>L ra Vng trn</li>
     32 <li>Chuyn tip hot ng</li>
     33 <li>Chuyn ng cong</li>
     34 <li>Thay i trng thi xem</li>
     35 </ul>
     36 
     37 
     38 <h2 id="Touch">Ty chnh Phn hi Chm</h2>
     39 
     40 <p>Phn hi chm trong Material Design a ra mt xc nhn trc quan tc thi ti
     41 im tip xc khi ngi dng tng tc vi cc phn t UI. Hot hnh phn hi chm mc nh
     42 cho nt s s dng lp {@link android.graphics.drawable.RippleDrawable} mi  chuyn tip
     43 gia cc trng thi khc nhau bng hiu ng gn sng.</p>
     44 
     45 <p>Trong hu ht trng hp, bn nn p dng tnh nng ny trong tp XML dng xem ca mnh bng cch ch nh nn
     46 dng xem l:</p>
     47 
     48 <ul>
     49 <li><code>?android:attr/selectableItemBackground</code> cho gn sng c gii hn.</li>
     50 <li><code>?android:attr/selectableItemBackgroundBorderless</code> cho gn sng lan ra ngoi
     51 dng xem. Hiu ng s c v ln v c gii hn bi dng xem m gn nht c nn
     52 khng rng.</li>
     53 </ul>
     54 
     55 <p class="note"><strong>Lu :</strong> <code>selectableItemBackgroundBorderless</code> l mt thuc tnh
     56 mi c gii thiu trong API mc 21.</p>
     57 
     58 
     59 <p>Hoc, bn c th nh ngha {@link android.graphics.drawable.RippleDrawable}
     60 lm ti nguyn XML bng cch s dng phn t <code>ripple</code>.</p>
     61 
     62 <p>Bn c th gn mt mu cho cc i tng {@link android.graphics.drawable.RippleDrawable}.  thay i
     63 mu phn hi chm mc nh, hy s dng thuc tnh <code>android:colorControlHighlight</code>
     64 ca ch .</p>
     65 
     66 <p> bit thm thng tin, hy xem ti liu tham kho API cho lp {@link
     67 android.graphics.drawable.RippleDrawable}.</p>
     68 
     69 
     70 <h2 id="Reveal">S dng Hiu ng L ra</h2>
     71 
     72 <p>Hot hnh l ra m bo tnh lin tc trc quan cho ngi dng khi bn hin hoc n mt nhm phn t
     73 UI. Phng thc {@link android.view.ViewAnimationUtils#createCircularReveal
     74 ViewAnimationUtils.createCircularReveal()} cho php bn to hiu ng hot hnh mt vng trn ct hnh
     75  l ra hoc n mt dng xem.</p>
     76 
     77 <p> l ra mt dng xem n trc  bng hiu ng ny:</p>
     78 
     79 <pre>
     80 // previously invisible view
     81 View myView = findViewById(R.id.my_view);
     82 
     83 // get the center for the clipping circle
     84 int cx = (myView.getLeft() + myView.getRight()) / 2;
     85 int cy = (myView.getTop() + myView.getBottom()) / 2;
     86 
     87 // get the final radius for the clipping circle
     88 int finalRadius = Math.max(myView.getWidth(), myView.getHeight());
     89 
     90 // create the animator for this view (the start radius is zero)
     91 Animator anim =
     92     ViewAnimationUtils.createCircularReveal(myView, cx, cy, 0, finalRadius);
     93 
     94 // make the view visible and start the animation
     95 myView.setVisibility(View.VISIBLE);
     96 anim.start();
     97 </pre>
     98 
     99 <p> n mt dng xem hin th trc  bng hiu ng ny:</p>
    100 
    101 <pre>
    102 // previously visible view
    103 final View myView = findViewById(R.id.my_view);
    104 
    105 // get the center for the clipping circle
    106 int cx = (myView.getLeft() + myView.getRight()) / 2;
    107 int cy = (myView.getTop() + myView.getBottom()) / 2;
    108 
    109 // get the initial radius for the clipping circle
    110 int initialRadius = myView.getWidth();
    111 
    112 // create the animation (the final radius is zero)
    113 Animator anim =
    114     ViewAnimationUtils.createCircularReveal(myView, cx, cy, initialRadius, 0);
    115 
    116 // make the view invisible when the animation is done
    117 anim.addListener(new AnimatorListenerAdapter() {
    118     &#64;Override
    119     public void onAnimationEnd(Animator animation) {
    120         super.onAnimationEnd(animation);
    121         myView.setVisibility(View.INVISIBLE);
    122     }
    123 });
    124 
    125 // start the animation
    126 anim.start();
    127 </pre>
    128 
    129 
    130 <h2 id="Transitions">Ty chnh Chuyn tip Hot ng</h2>
    131 
    132 <!-- shared transition video -->
    133 <div style="width:290px;margin-left:35px;float:right">
    134   <div class="framed-nexus5-port-span-5">
    135   <video class="play-on-hover" autoplay="">
    136     <source src="{@docRoot}design/material/videos/ContactsAnim.mp4">
    137     <source src="{@docRoot}design/material/videos/ContactsAnim.webm">
    138     <source src="{@docRoot}design/material/videos/ContactsAnim.ogv">
    139   </video>
    140   </div>
    141   <div style="font-size:10pt;margin-left:20px;margin-bottom:30px">
    142     <p class="img-caption" style="margin-top:3px;margin-bottom:10px"><strong>Hnh 1</strong> - Chuyn tip
    143     vi nhng phn t chung.</p>
    144     <em> pht li phim, nhp vo mn hnh thit b</em>
    145   </div>
    146 </div>
    147 
    148 <p>Chuyn tip hot ng trong cc ng dng theo phong cch material design cung cp kt ni trc quan gia cc trng thi khc nhau
    149 thng qua chuyn ng v chuyn i gia nhng phn t hay dng. Bn c th quy nh hot hnh ty chnh cho
    150 cc chuyn tip ra vo v chuyn tip phn t chung gia cc hot ng.</p>
    151 
    152 <ul>
    153 <li>Chuyn tip <strong>vo</strong> xc nh cc dng xem trong mt hot ng s vo cnh  nh th no.
    154 V d, trong chuyn tip vo dng <em>n tung</em>, dng xem s vo cnh t bn ngoi
    155 v bay v pha chnh gia mn hnh.</li>
    156 
    157 <li>Chuyn tip <strong>ra</strong> xc nh cc dng xem trong mt hot ng s ra khi cnh nh th no. V
    158  d, trong chuyn tip ra kiu <em>n tung</em>, dng xem s ra khi cnh t
    159 trung tm.</li>
    160 
    161 <li>Chuyn tip <strong>phn t chung</strong> xc nh cc dng xem chung gia hai hot ng
    162 s chuyn tip nh th no gia nhng hot ng ny. V d, nu hai hot ng c cng
    163 hnh nh  cc v tr v kch c khc nhau, chuyn tip phn t chung <em>changeImageTransform</em>
    164 s th hin v co gin hnh nh mt cch mt m gia nhng hot ng ny.</li>
    165 </ul>
    166 
    167 <p>Android 5.0 (API mc 21) h tr nhng chuyn tip ra vo sau:</p>
    168 
    169 <ul>
    170 <li><em>n tung</em> - Di chuyn cc dng xem vo hoc ra khi chnh gia cnh.</li>
    171 <li><em>trt</em> - Di chuyn cc dng xem vo hoc ra t mt trong cc mp ca cnh.</li>
    172 <li><em>m dn</em> - Thm hoc g b dng xem khi cnh bng cch thay i  m c ca n.</li>
    173 </ul>
    174 
    175 <p>Bt c chuyn tip no m rng lp {@link android.transition.Visibility} u c h tr
    176 nh mt chuyn tip vo hoc ra.  bit thm thng tin, hy xem ti liu tham kho API cho lp
    177 {@link android.transition.Transition}.</p>
    178 
    179 <p>Android 5.0 (API mc 21) cng h tr nhng chuyn tip phn t chung ny:</p>
    180 
    181 <ul>
    182 <li><em>changeBounds</em> - To hiu ng hot hnh cc thay i trong gii hn b tr ca dng xem mc tiu.</li>
    183 <li><em>changeClipBounds</em> - To hiu ng hot hnh cc thay i trong gii hn ct hnh ca dng xem mc tiu.</li>
    184 <li><em>changeTransform</em> - To hiu ng hot hnh cc thay i v co gin v xoay dng xem mc tiu.</li>
    185 <li><em>changeImageTransform</em> - To hiu ng hot hnh cc thay i v kch c v co gin ca nh mc tiu.</li>
    186 </ul>
    187 
    188 <p>Khi bn cho php chuyn tip hot ng trong ng dng ca mnh, chuyn tip m dn cho cross-fading
    189 mc nh s c kch hot gia cc hot ng ra vo.</p>
    190 
    191 <img src="{@docRoot}training/material/images/SceneTransition.png" alt="" width="600" height="405" style="margin-top:20px" />
    192 <p class="img-caption">
    193  <strong>Hnh 2</strong> - Chuyn tip cnh vi mt phn t chung.
    194 </p>
    195 
    196 <h3>Quy nh chuyn tip ty chnh</h3>
    197 
    198 <p>Trc tin, cho php chuyn tip ni dung ca s bng thuc tnh <code>android:windowContentTransitions</code>
    199 khi bn nh ngha mt kiu k tha t ch  material. Bn cng c th quy nh chuyn tip
    200 ra, vo v phn t chung trong nh ngha kiu ca mnh:</p>
    201 
    202 <pre>
    203 &lt;style name="BaseAppTheme" parent="android:Theme.Material">
    204   &lt;!-- enable window content transitions -->
    205   &lt;item name="android:windowContentTransitions">true&lt;/item>
    206 
    207   &lt;!-- specify enter and exit transitions -->
    208   &lt;item name="android:windowEnterTransition">@transition/explode&lt;/item>
    209   &lt;item name="android:windowExitTransition">@transition/explode&lt;/item>
    210 
    211   &lt;!-- specify shared element transitions -->
    212   &lt;item name="android:windowSharedElementEnterTransition">
    213     &#64;transition/change_image_transform&lt;/item>
    214   &lt;item name="android:windowSharedElementExitTransition">
    215     &#64;transition/change_image_transform&lt;/item>
    216 &lt;/style>
    217 </pre>
    218 
    219 <p>Chuyn tip <code>change_image_transform</code> trong v d ny c nh ngha nh sau:</p>
    220 
    221 <pre>
    222 &lt;!-- res/transition/change_image_transform.xml -->
    223 &lt;!-- (see also Shared Transitions below) -->
    224 &lt;transitionSet xmlns:android="http://schemas.android.com/apk/res/android">
    225   &lt;changeImageTransform/>
    226 &lt;/transitionSet>
    227 </pre>
    228 
    229 <p>Phn t <code>changeImageTransform</code> tng ng vi lp
    230 {@link android.transition.ChangeImageTransform}.  bit thm thng tin, hy xem ti liu tham kho API
    231 cho {@link android.transition.Transition}.</p>
    232 
    233 <p>Thay vo ,  cho php chuyn tip ni dung ca s trong m ca bn, hy gi phng thc
    234 {@link android.view.Window#requestFeature Window.requestFeature()}:</p>
    235 
    236 <pre>
    237 // inside your activity (if you did not enable transitions in your theme)
    238 getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
    239 
    240 // set an exit transition
    241 getWindow().setExitTransition(new Explode());
    242 </pre>
    243 
    244 <p> quy nh chuyn tip trong m ca bn, hy gi nhng phng thc ny bng i tng {@link
    245 android.transition.Transition}:</p>
    246 
    247 <ul>
    248   <li>{@link android.view.Window#setEnterTransition Window.setEnterTransition()}</li>
    249   <li>{@link android.view.Window#setExitTransition Window.setExitTransition()}</li>
    250   <li>{@link android.view.Window#setSharedElementEnterTransition
    251       Window.setSharedElementEnterTransition()}</li>
    252   <li>{@link android.view.Window#setSharedElementExitTransition
    253       Window.setSharedElementExitTransition()}</li>
    254 </ul>
    255 
    256 <p>Phng thc {@link android.view.Window#setExitTransition setExitTransition()} v {@link
    257 android.view.Window#setSharedElementExitTransition setSharedElementExitTransition()} nh ngha
    258 chuyn tip ra cho hot ng gi. Phng thc {@link android.view.Window#setEnterTransition
    259 setEnterTransition()} v {@link android.view.Window#setSharedElementEnterTransition
    260 setSharedElementEnterTransition()} nh ngha chuyn tip vo cho hot ng c gi.</p>
    261 
    262 <p> c y  hiu ng ca mt chuyn tip, bn phi cho php chuyn tip ni dung ca s trn c hot ng
    263 gi v c gi. Nu khng, hot ng gi s bt u chuyn tip ra,
    264 nhng khi  bn s thy chuyn tip ca s (nh co gin v m dn).</p>
    265 
    266 <p> bt u mt chuyn tip vo ngay khi c th, hy s dng phng thc
    267 {@link android.view.Window#setAllowEnterTransitionOverlap Window.setAllowEnterTransitionOverlap()}
    268 trn hot ng c gi. N cho php bn c chuyn tip vo n tng hn.</p>
    269 
    270 <h3>Bt u mt hot ng bng chuyn tip</h3>
    271 
    272 <p>Nu bn cho php chuyn tip v t chuyn tip ra cho mt hot ng, chuyn tip s c
    273 kch hot khi bn khi chy mt hot ng khc nh sau:</p>
    274 
    275 <pre>
    276 startActivity(intent,
    277               ActivityOptions.makeSceneTransitionAnimation(this).toBundle());
    278 </pre>
    279 
    280 <p>Nu bn t mt chuyn tip vo cho hot ng th hai, chuyn tip ny cng c kch hot khi hot ng
    281 bt u.  v hiu ho chuyn tip khi bn bt u mt hot ng khc, hy cung cp
    282 mt nhm ty chn <code>null</code>.</p>
    283 
    284 <h3>Bt u mt hot ng bng mt phn t chung</h3>
    285 
    286 <p> to mt hot hnh chuyn tip mn hnh gia hai hot ng c mt phn t chung:</p>
    287 
    288 <ol>
    289 <li>Cho php chuyn tip ni dung ca s trong ch  ca bn.</li>
    290 <li>Quy nh mt chuyn tip phn t chung trong kiu ca bn.</li>
    291 <li>nh ngha chuyn tip ca bn di dng mt ti nguyn XML.</li>
    292 <li>Gn mt tn chung cho cc phn t chung  c hai b tr bng thuc tnh
    293     <code>android:transitionName</code>.</li>
    294 <li>S dng phng thc {@link android.app.ActivityOptions#makeSceneTransitionAnimation
    295 ActivityOptions.makeSceneTransitionAnimation()}.</li>
    296 </ol>
    297 
    298 <pre>
    299 // get the element that receives the click event
    300 final View imgContainerView = findViewById(R.id.img_container);
    301 
    302 // get the common element for the transition in this activity
    303 final View androidRobotView = findViewById(R.id.image_small);
    304 
    305 // define a click listener
    306 imgContainerView.setOnClickListener(new View.OnClickListener() {
    307     &#64;Override
    308     public void onClick(View view) {
    309         Intent intent = new Intent(this, Activity2.class);
    310         // create the transition animation - the images in the layouts
    311         // of both activities are defined with android:transitionName="robot"
    312         ActivityOptions options = ActivityOptions
    313             .makeSceneTransitionAnimation(this, androidRobotView, "robot");
    314         // start the new activity
    315         startActivity(intent, options.toBundle());
    316     }
    317 });
    318 </pre>
    319 
    320 <p>i vi cc dng xem ng dng chung m bn khi to trong m ca mnh, hy s dng phng thc
    321 {@link android.view.View#setTransitionName View.setTransitionName()}  quy nh mt
    322 tn phn t chung trong c hai hot ng.</p>
    323 
    324 <p> o ngc hot hnh chuyn tip cnh khi bn kt thc hot ng th hai, hy gi phng thc
    325 {@link android.app.Activity#finishAfterTransition Activity.finishAfterTransition()}
    326 thay v {@link android.app.Activity#finish Activity.finish()}.</p>
    327 
    328 <h3>Bt u mt hot ng bng nhiu phn t chung</h3>
    329 
    330 <p> to mt hot hnh chuyn tip cnh gia hai hot ng c nhiu hn mt phn t
    331 chung, hy nh ngha cc phn t chung trong c hai b tr bng thuc tnh <code>android:transitionName</code>
    332  (hoc s dng phng thc {@link android.view.View#setTransitionName View.setTransitionName()}
    333 trong c hai hot ng), v to mt i tng {@link android.app.ActivityOptions} nh sau:</p>
    334 
    335 <pre>
    336 ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(this,
    337         Pair.create(view1, "agreedName1"),
    338         Pair.create(view2, "agreedName2"));
    339 </pre>
    340 
    341 
    342 <h2 id="CurvedMotion">S dng Chuyn ng Cong</h2>
    343 
    344 <p>Hot hnh theo phong cch material design ph thuc vo ng cong lm mu hnh ni suy thi gian
    345 v chuyn ng khng gian. Vi Android 5.0 (API mc 21) tr ln, bn c th nh ngha ng cong nh thi ty chnh v
    346 mu hnh chuyn ng cong cho hot hnh.</p>
    347 
    348 <p>Lp {@link android.view.animation.PathInterpolator} l mt hm ni suy mi da trn ng cong
    349 Bzier hoc i tng {@link android.graphics.Path}. Hm ni suy ny quy nh mt ng cong chuyn ng
    350 trong mt hnh vung 1x1, vi cc im neo ti (0,0) v (1,1) cng cc im kim sot c quy nh bng cch s dng
    351 cc tham i ca hm dng. Bn cng c th nh ngha mt hm ni suy ng dn di dng ti nguyn XML:</p>
    352 
    353 <pre>
    354 &lt;pathInterpolator xmlns:android="http://schemas.android.com/apk/res/android"
    355     android:controlX1="0.4"
    356     android:controlY1="0"
    357     android:controlX2="1"
    358     android:controlY2="1"/>
    359 </pre>
    360 
    361 <p>H thng cung cp ti nguyn XML cho ba ng cong c bn trong c t
    362 material design:</p>
    363 
    364 <ul>
    365   <li><code>&#64;interpolator/fast_out_linear_in.xml</code></li>
    366   <li><code>&#64;interpolator/fast_out_slow_in.xml</code></li>
    367   <li><code>&#64;interpolator/linear_out_slow_in.xml</code></li>
    368 </ul>
    369 
    370 <p>Bn c th chuyn mt i tng {@link android.view.animation.PathInterpolator} ti phng thc {@link
    371 android.animation.Animator#setInterpolator Animator.setInterpolator()}.</p>
    372 
    373 <p>Lp {@link android.animation.ObjectAnimator} c cc hm dng mi cho php bn to hiu ng hot hnh
    374 cho cc ta  dc theo mt ng dn bng hai hoc nhiu thuc tnh ng thi. V d, trnh to hot hnh sau
    375 s dng mt i tng {@link android.graphics.Path}  to hiu ng hot hnh cho thuc tnh X v Y ca mt dng xem:</p>
    376 
    377 <pre>
    378 ObjectAnimator mAnimator;
    379 mAnimator = ObjectAnimator.ofFloat(view, View.X, View.Y, path);
    380 ...
    381 mAnimator.start();
    382 </pre>
    383 
    384 
    385 <h2 id="ViewState">To Hiu ng Hot hnh Thay i Trng thi Xem</h2>
    386 
    387 <p>Lp {@link android.animation.StateListAnimator} cho php bn nh ngha trnh to hot hnh  chy khi
    388 trng thi ca dng xem thay i. V d sau cho bit cch nh ngha mt {@link
    389 android.animation.StateListAnimator}  di dng ti nguyn XML:</p>
    390 
    391 <pre>
    392 &lt;!-- animate the translationZ property of a view when pressed -->
    393 &lt;selector xmlns:android="http://schemas.android.com/apk/res/android">
    394   &lt;item android:state_pressed="true">
    395     &lt;set>
    396       &lt;objectAnimator android:propertyName="translationZ"
    397         android:duration="@android:integer/config_shortAnimTime"
    398         android:valueTo="2dp"
    399         android:valueType="floatType"/>
    400         &lt;!-- you could have other objectAnimator elements
    401              here for "x" and "y", or other properties -->
    402     &lt;/set>
    403   &lt;/item>
    404   &lt;item android:state_enabled="true"
    405     android:state_pressed="false"
    406     android:state_focused="true">
    407     &lt;set>
    408       &lt;objectAnimator android:propertyName="translationZ"
    409         android:duration="100"
    410         android:valueTo="0"
    411         android:valueType="floatType"/>
    412     &lt;/set>
    413   &lt;/item>
    414 &lt;/selector>
    415 </pre>
    416 
    417 <p> gn km hot hnh trng thi dng xem ty chnh vo mt dng xem, hy nh ngha mt trnh to hot hnh bng cch s dng phn t
    418 <code>selector</code> trong mt tp ti nguyn XML nh trong v d ny, v gn n cho dng xem
    419 ca bn bng thuc tnh <code>android:stateListAnimator</code>.  gn mt trnh to hot hnh danh sch trng thi
    420 cho mt dng xem trong m ca bn, hy s dng phng thc {@link android.animation.AnimatorInflater#loadStateListAnimator
    421 AnimationInflater.loadStateListAnimator()} v gn trnh to hot hnh cho dng xem ca bn bng phng thc
    422 {@link android.view.View#setStateListAnimator View.setStateListAnimator()}.</p>
    423 
    424 <p>Khi ch  ca bn m rng ra ch  material, cc nt s c hot hnh Z theo mc nh.  trnh hnh vi
    425 ny trong nt ca bn, hy t thuc tnh <code>android:stateListAnimator</code> thnh
    426 <code>@null</code>.</p>
    427 
    428 <p>Lp {@link android.graphics.drawable.AnimatedStateListDrawable} cho php bn to cc ni dung v c
    429  hin th hot hnh gia cc thay i trng thi ca dng xem c lin kt. Mt s widget h thng trong
    430 Android 5.0 s dng nhng hot hnh ny theo mc nh. V d sau cho bit cch
    431 cch nh ngha {@link android.graphics.drawable.AnimatedStateListDrawable} di dng ti nguyn XML:</p>
    432 
    433 <pre>
    434 &lt;!-- res/drawable/myanimstatedrawable.xml -->
    435 &lt;animated-selector
    436     xmlns:android="http://schemas.android.com/apk/res/android">
    437 
    438     &lt;!-- provide a different drawable for each state-->
    439     &lt;item android:id="@+id/pressed" android:drawable="@drawable/drawableP"
    440         android:state_pressed="true"/>
    441     &lt;item android:id="@+id/focused" android:drawable="@drawable/drawableF"
    442         android:state_focused="true"/>
    443     &lt;item android:id="@id/default"
    444         android:drawable="@drawable/drawableD"/>
    445 
    446     &lt;!-- specify a transition -->
    447     &lt;transition android:fromId="@+id/default" android:toId="@+id/pressed">
    448         &lt;animation-list>
    449             &lt;item android:duration="15" android:drawable="@drawable/dt1"/>
    450             &lt;item android:duration="15" android:drawable="@drawable/dt2"/>
    451             ...
    452         &lt;/animation-list>
    453     &lt;/transition>
    454     ...
    455 &lt;/animated-selector>
    456 </pre>
    457 
    458 
    459 <h2 id="AnimVector">To Hiu ng Hot hnh Ni dung v c Vc-t</h2>
    460 
    461 <p><a href="{@docRoot}training/material/drawables.html#VectorDrawables">Ni dung v c Vc-t</a> s co gin c
    462 m khng lm mt  sc nt. Lp {@link android.graphics.drawable.AnimatedVectorDrawable}
    463 cho php bn to hiu ng hot hnh cc thuc tnh ca ni dung v c vc-t.</p>
    464 
    465 <p>Thng th bn nh ngha ni dung v c vc-t hot hnh theo ba tp XML:</p>
    466 
    467 <ul>
    468 <li>Ni dung v c vc-t vi phn t <code>&lt;vector&gt;</code> trong
    469 <code>res/drawable/</code></li>
    470 <li>Ni dung v c vc-t hot hnh vi phn t <code>&lt;animated-vector&gt;</code> trong
    471 <code>res/drawable/</code></li>
    472 <li>Mt hoc nhiu trnh to hot hnh i tng vi phn t <code>&lt;objectAnimator&gt;</code> trong
    473 <code>res/anim/</code></li>
    474 </ul>
    475 
    476 <p>Ni dung v c vc-t hot hnh c th to hiu ng hot hnh cc thuc tnh ca phn t <code>&lt;group&gt;</code> v
    477 <code>&lt;path&gt;</code>. Phn t <code>&lt;group&gt;</code> nh ngha mt b
    478 ng dn hoc nhm ph v phn t <code>&lt;path&gt;</code> nh ngha cc ng dn s c v.</p>
    479 
    480 <p>Khi nh ngha mt ni dung v c vc-t m bn mun to hiu ng hot hnh, hy s dng thuc tnh <code>android:name</code>
    481  gn mt tn duy nht cho cc nhm v ng dn, sao cho bn c th tham chiu ti chng t cc nh ngha
    482 trnh to hot hnh ca mnh. V d:</p>
    483 
    484 <pre>
    485 &lt;!-- res/drawable/vectordrawable.xml -->
    486 &lt;vector xmlns:android="http://schemas.android.com/apk/res/android"
    487     android:height="64dp"
    488     android:width="64dp"
    489     android:viewportHeight="600"
    490     android:viewportWidth="600">
    491     &lt;group
    492         <strong>android:name="rotationGroup"</strong>
    493         android:pivotX="300.0"
    494         android:pivotY="300.0"
    495         android:rotation="45.0" >
    496         &lt;path
    497             <strong>android:name="v"</strong>
    498             android:fillColor="#000000"
    499             android:pathData="M300,70 l 0,-70 70,70 0,0 -70,70z" />
    500     &lt;/group>
    501 &lt;/vector>
    502 </pre>
    503 
    504 <p>nh ngha ni dung v c vc-t hot hnh s tham chiu ti cc nhm v ng dn trong ni dung v c vc-t theo
    505 tn ca chng:</p>
    506 
    507 <pre>
    508 &lt;!-- res/drawable/animvectordrawable.xml -->
    509 &lt;animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
    510   android:drawable="@drawable/vectordrawable" >
    511     &lt;target
    512         android:name="rotationGroup"
    513         android:animation="@anim/rotation" />
    514     &lt;target
    515         android:name="v"
    516         android:animation="@anim/path_morph" />
    517 &lt;/animated-vector>
    518 </pre>
    519 
    520 <p>nh ngha hot hnh biu din cc i tng {@link android.animation.ObjectAnimator} hoc {@link
    521 android.animation.AnimatorSet}. Trnh to hot hnh u tin trong v d ny s xoay nhm
    522 i tng 360 :</p>
    523 
    524 <pre>
    525 &lt;!-- res/anim/rotation.xml -->
    526 &lt;objectAnimator
    527     android:duration="6000"
    528     android:propertyName="rotation"
    529     android:valueFrom="0"
    530     android:valueTo="360" />
    531 </pre>
    532 
    533 <p>Trnh to hot hnh th hai trong v d ny s i dng ng dn ca ni dung v c vc-t t hnh ny sang
    534 hnh khc. C hai ng dn u phi tng thch vi vic i dng: chng phi c cng s lnh
    535 v cng s lng tham s cho tng lnh.</p>
    536 
    537 <pre>
    538 &lt;!-- res/anim/path_morph.xml -->
    539 &lt;set xmlns:android="http://schemas.android.com/apk/res/android">
    540     &lt;objectAnimator
    541         android:duration="3000"
    542         android:propertyName="pathData"
    543         android:valueFrom="M300,70 l 0,-70 70,70 0,0   -70,70z"
    544         android:valueTo="M300,70 l 0,-70 70,0  0,140 -70,0 z"
    545         android:valueType="pathType" />
    546 &lt;/set>
    547 </pre>
    548 
    549 <p> bit thm thng tin, hy xem ti liu tham kho API cho {@link
    550 android.graphics.drawable.AnimatedVectorDrawable}.</p>
    551