blob: 9299d3c931a89579f14f49e7ecf025137c312bb0 [file] [log] [blame]
page.title=Định nghĩa Hot hình Tùy chnh
@jd:body
<div id="tb-wrapper">
<div id="tb">
<h2>Bài hc này hướng dn bn cách</h2>
<ol>
<li><a href="#Touch">Tùy chnh Phn hi Chm</a></li>
<li><a href="#Reveal">S dng Hiu ng L ra</a></li>
<li><a href="#Transitions">Tùy chnh Chuyn tiếp Hot động</a></li>
<li><a href="#ViewState">To Hiu ng Hot hình Thay đổi Trng thái Xem</a></li>
<li><a href="#AnimVector">To Hiu ng Hot hình Ni dung v được Véc-tơ</a></li>
</ol>
<h2>Bn cũng nên đọc</h2>
<ul>
<li><a href="http://www.google.com/design/spec">Đặc t phong cách Material Design</a></li>
<li><a href="{@docRoot}design/material/index.html">Material Design trên Android</a></li>
</ul>
</div>
</div>
<p>Hot hình theo phong cách material design phn hi hành động ca người dùng và cung cp
tính liên tc trc quan khi người dùng tương tác vi ng dng ca bn. Giao din material cung cp mt s hot hình
mc định cho các nút và chuyn tiếp hot động, và Android 5.0 (API mc 21) và cao hơn cho phép bn tùy chnh
nhng hot hình này và to các hot hình mi:</p>
<ul>
<li>Phn hi chm</li>
<li>L ra Vòng tròn</li>
<li>Chuyn tiếp hot động</li>
<li>Chuyn động cong</li>
<li>Thay đổi trng thái xem</li>
</ul>
<h2 id="Touch">Tùy chnh Phn hi Chm</h2>
<p>Phn hi chm trong Material Design đưa ra mt xác nhn trc quan tc thi ti
đim tiếp xúc khi người dùng tương tác vi các phn t UI. Hot hình phn hi chm mc định
cho nút s s dng lp {@link android.graphics.drawable.RippleDrawable} mi để chuyn tiếp
gia các trng thái khác nhau bng hiu ng gn sóng.</p>
<p>Trong hu hết trường hp, bn nên áp dng tính năng này trong tp XML dng xem ca mình bng cách ch định nn
dng xem là:</p>
<ul>
<li><code>?android:attr/selectableItemBackground</code> cho gợn sóng có giới hạn.</li>
<li><code>?android:attr/selectableItemBackgroundBorderless</code> cho gn sóng lan ra ngoài
dng xem. Hiu ng s được v lên và được gii hn bi dng xem m gn nht có nn
không rng.</li>
</ul>
<p class="note"><strong>Lưu ý:</strong> <code>selectableItemBackgroundBorderless</code> là mt thuc tính
mi được gii thiu trong API mc 21.</p>
<p>Hoc, bn có th định nghĩa {@link android.graphics.drawable.RippleDrawable}
làm tài nguyên XML bng cách s dng phn t <code>ripple</code>.</p>
<p>Bn có th gán mt màu cho các đối tượng {@link android.graphics.drawable.RippleDrawable}. Để thay đổi
màu phn hi chm mc định, hãy s dng thuc tính <code>android:colorControlHighlight</code>
ca ch đề.</p>
<p>Để biết thêm thông tin, hãy xem tài liu tham kho API cho lp {@link
android.graphics.drawable.RippleDrawable}.</p>
<h2 id="Reveal">S dng Hiu ng L ra</h2>
<p>Hot hình l ra đảm bo tính liên tc trc quan cho người dùng khi bn hin hoc n mt nhóm phn t
UI. Phương thc {@link android.view.ViewAnimationUtils#createCircularReveal
ViewAnimationUtils.createCircularReveal()} cho phép bn to hiu ng hot hình mt vòng tròn ct hình
để l ra hoc n mt dng xem.</p>
<p>Để l ra mt dng xem n trước đó bng hiu ng này:</p>
<pre>
// previously invisible view
View myView = findViewById(R.id.my_view);
// get the center for the clipping circle
int cx = (myView.getLeft() + myView.getRight()) / 2;
int cy = (myView.getTop() + myView.getBottom()) / 2;
// get the final radius for the clipping circle
int finalRadius = Math.max(myView.getWidth(), myView.getHeight());
// create the animator for this view (the start radius is zero)
Animator anim =
ViewAnimationUtils.createCircularReveal(myView, cx, cy, 0, finalRadius);
// make the view visible and start the animation
myView.setVisibility(View.VISIBLE);
anim.start();
</pre>
<p>Để n mt dng xem hin th trước đó bng hiu ng này:</p>
<pre>
// previously visible view
final View myView = findViewById(R.id.my_view);
// get the center for the clipping circle
int cx = (myView.getLeft() + myView.getRight()) / 2;
int cy = (myView.getTop() + myView.getBottom()) / 2;
// get the initial radius for the clipping circle
int initialRadius = myView.getWidth();
// create the animation (the final radius is zero)
Animator anim =
ViewAnimationUtils.createCircularReveal(myView, cx, cy, initialRadius, 0);
// make the view invisible when the animation is done
anim.addListener(new AnimatorListenerAdapter() {
&#64;Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
myView.setVisibility(View.INVISIBLE);
}
});
// start the animation
anim.start();
</pre>
<h2 id="Transitions">Tùy chnh Chuyn tiếp Hot động</h2>
<!-- shared transition video -->
<div style="width:290px;margin-left:35px;float:right">
<div class="framed-nexus5-port-span-5">
<video class="play-on-hover" autoplay="">
<source src="{@docRoot}design/material/videos/ContactsAnim.mp4">
<source src="{@docRoot}design/material/videos/ContactsAnim.webm">
<source src="{@docRoot}design/material/videos/ContactsAnim.ogv">
</video>
</div>
<div style="font-size:10pt;margin-left:20px;margin-bottom:30px">
<p class="img-caption" style="margin-top:3px;margin-bottom:10px"><strong>Hình 1</strong> - Chuyn tiếp
vi nhng phn t chung.</p>
<em>Để phát li phim, nhp vào màn hình thiết bị</em>
</div>
</div>
<p>Chuyn tiếp hot động trong các ng dng theo phong cách material design cung cp kết ni trc quan gia các trng thái khác nhau
thông qua chuyn động và chuyn đổi gia nhng phn t hay dùng. Bn có th quy định hot hình tùy chnh cho
các chuyn tiếp ra vào và chuyn tiếp phn t chung gia các hot động.</p>
<ul>
<li>Chuyn tiếp <strong>vào</strong> xác định các dng xem trong mt hot động s vào cnh đó như thế nào.
Ví dụ, trong chuyn tiếp vào dng <em>n tung</em>, dng xem s vào cnh t bên ngoài
và bay v phía chính gia màn hình.</li>
<li>Chuyn tiếp <strong>ra</strong> xác định các dng xem trong mt hot động s ra khi cnh như thế nào. Ví
dụ, trong chuyn tiếp ra kiu <em>n tung</em>, dng xem s ra khi cnh t
trung tâm.</li>
<li>Chuyn tiếp <strong>phn t chung</strong> xác định các dng xem chung gia hai hot động
s chuyn tiếp như thế nào gia nhng hot động này. Ví dụ, nếu hai hot động có cùng
hình nh các v trí và kích c khác nhau, chuyn tiếp phn t chung <em>changeImageTransform</em>
s th hin và co giãn hình nh mt cách mượt mà gia nhng hot động này.</li>
</ul>
<p>Android 5.0 (API mc 21) h tr nhng chuyn tiếp ra vào sau:</p>
<ul>
<li><em>n tung</em> - Di chuyển các dạng xem vào hoặc ra khỏi chính giữa cảnh.</li>
<li><em>trượt</em> - Di chuyển các dạng xem vào hoặc ra từ một trong các mép của cảnh.</li>
<li><em>m dn</em> - Thêm hoặc gỡ bỏ dạng xem khỏi cảnh bằng cách thay đổi độ mờ đục của nó.</li>
</ul>
<p>Bt c chuyn tiếp nào m rng lp {@link android.transition.Visibility} đều được h tr
như mt chuyn tiếp vào hoc ra. Để biết thêm thông tin, hãy xem tài liu tham kho API cho lp
{@link android.transition.Transition}.</p>
<p>Android 5.0 (API mc 21) cũng h tr nhng chuyn tiếp phn t chung này:</p>
<ul>
<li><em>changeBounds</em> - Tạo hiệu ứng hoạt hình các thay đổi trong giới hạn bố trí của dạng xem mục tiêu.</li>
<li><em>changeClipBounds</em> - Tạo hiệu ứng hoạt hình các thay đổi trong giới hạn cắt hình của dạng xem mục tiêu.</li>
<li><em>changeTransform</em> - Tạo hiệu ứng hoạt hình các thay đổi về co giãn và xoay dạng xem mục tiêu.</li>
<li><em>changeImageTransform</em> - Tạo hiệu ứng hoạt hình các thay đổi về kích cỡ và co giãn của ảnh mục tiêu.</li>
</ul>
<p>Khi bn cho phép chuyn tiếp hot động trong ng dng ca mình, chuyn tiếp m dn chéo cross-fading
mc định s được kích hot gia các hot động ra vào.</p>
<img src="{@docRoot}training/material/images/SceneTransition.png" alt="" width="600" height="405" style="margin-top:20px" />
<p class="img-caption">
  <strong>Hình 2</strong> - Chuyn tiếp cnh vi mt phn t chung.
</p>
<h3>Quy định chuyn tiếp tùy chnh</h3>
<p>Trước tiên, cho phép chuyn tiếp ni dung ca s bng thuc tính <code>android:windowContentTransitions</code>
khi bn định nghĩa mt kiu kế tha t ch đề material. Bn cũng có th quy định chuyn tiếp
ra, vào và phn t chung trong định nghĩa kiu ca mình:</p>
<pre>
&lt;style name="BaseAppTheme" parent="android:Theme.Material">
&lt;!-- enable window content transitions -->
&lt;item name="android:windowContentTransitions">true&lt;/item>
&lt;!-- specify enter and exit transitions -->
&lt;item name="android:windowEnterTransition">@transition/explode&lt;/item>
&lt;item name="android:windowExitTransition">@transition/explode&lt;/item>
&lt;!-- specify shared element transitions -->
&lt;item name="android:windowSharedElementEnterTransition">
&#64;transition/change_image_transform&lt;/item>
&lt;item name="android:windowSharedElementExitTransition">
&#64;transition/change_image_transform&lt;/item>
&lt;/style>
</pre>
<p>Chuyn tiếp <code>change_image_transform</code> trong ví dụ này được định nghĩa như sau:</p>
<pre>
&lt;!-- res/transition/change_image_transform.xml -->
&lt;!-- (see also Shared Transitions below) -->
&lt;transitionSet xmlns:android="http://schemas.android.com/apk/res/android">
&lt;changeImageTransform/>
&lt;/transitionSet>
</pre>
<p>Phn t <code>changeImageTransform</code> tương ng vi lp
{@link android.transition.ChangeImageTransform}. Để biết thêm thông tin, hãy xem tài liu tham kho API
cho {@link android.transition.Transition}.</p>
<p>Thay vào đó, để cho phép chuyn tiếp ni dung ca s trong mã ca bn, hãy gi phương thc
{@link android.view.Window#requestFeature Window.requestFeature()}:</p>
<pre>
// inside your activity (if you did not enable transitions in your theme)
getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
// set an exit transition
getWindow().setExitTransition(new Explode());
</pre>
<p>Để quy định chuyn tiếp trong mã ca bn, hãy gi nhng phương thc này bng đối tượng {@link
android.transition.Transition}:</p>
<ul>
<li>{@link android.view.Window#setEnterTransition Window.setEnterTransition()}</li>
<li>{@link android.view.Window#setExitTransition Window.setExitTransition()}</li>
<li>{@link android.view.Window#setSharedElementEnterTransition
Window.setSharedElementEnterTransition()}</li>
<li>{@link android.view.Window#setSharedElementExitTransition
Window.setSharedElementExitTransition()}</li>
</ul>
<p>Phương thc {@link android.view.Window#setExitTransition setExitTransition()} và {@link
android.view.Window#setSharedElementExitTransition setSharedElementExitTransition()} định nghĩa
chuyn tiếp ra cho hot động gi. Phương thc {@link android.view.Window#setEnterTransition
setEnterTransition()} và {@link android.view.Window#setSharedElementEnterTransition
setSharedElementEnterTransition()} định nghĩa chuyn tiếp vào cho hot động được gi.</p>
<p>Để có đầy đủ hiu ng ca mt chuyn tiếp, bn phi cho phép chuyn tiếp ni dung ca s trên c hot động
gi và được gi. Nếu không, hot động gi s bt đầu chuyn tiếp ra,
nhưng khi đó bn s thy chuyn tiếp ca s (như co giãn và m dn).</p>
<p>Để bt đầu mt chuyn tiếp vào ngay khi có thể, hãy s dng phương thc
{@link android.view.Window#setAllowEnterTransitionOverlap Window.setAllowEnterTransitionOverlap()}
trên hot động được gi. Nó cho phép bn có chuyn tiếp vào n tượng hơn.</p>
<h3>Bt đầu mt hot động bng chuyn tiếp</h3>
<p>Nếu bn cho phép chuyn tiếp và đặt chuyn tiếp ra cho mt hot động, chuyn tiếp s được
kích hot khi bn khi chy mt hot động khác như sau:</p>
<pre>
startActivity(intent,
ActivityOptions.makeSceneTransitionAnimation(this).toBundle());
</pre>
<p>Nếu bn đặt mt chuyn tiếp vào cho hot động th hai, chuyn tiếp này cũng được kích hot khi hot động
bt đầu. Để vô hiu hoá chuyn tiếp khi bn bt đầu mt hot động khác, hãy cung cp
mt nhóm tùy chn <code>null</code>.</p>
<h3>Bt đầu mt hot động bng mt phn t chung</h3>
<p>Để to mt hot hình chuyn tiếp màn hình gia hai hot động có mt phn t chung:</p>
<ol>
<li>Cho phép chuyn tiếp ni dung ca s trong ch đề ca bn.</li>
<li>Quy định mt chuyn tiếp phn t chung trong kiu ca bn.</li>
<li>Định nghĩa chuyn tiếp ca bn dưới dng mt tài nguyên XML.</li>
<li>Gán mt tên chung cho các phn t chung c hai b trí bng thuc tính
<code>android:transitionName</code>.</li>
<li>S dng phương thc {@link android.app.ActivityOptions#makeSceneTransitionAnimation
ActivityOptions.makeSceneTransitionAnimation()}.</li>
</ol>
<pre>
// get the element that receives the click event
final View imgContainerView = findViewById(R.id.img_container);
// get the common element for the transition in this activity
final View androidRobotView = findViewById(R.id.image_small);
// define a click listener
imgContainerView.setOnClickListener(new View.OnClickListener() {
&#64;Override
public void onClick(View view) {
Intent intent = new Intent(this, Activity2.class);
// create the transition animation - the images in the layouts
// of both activities are defined with android:transitionName="robot"
ActivityOptions options = ActivityOptions
.makeSceneTransitionAnimation(this, androidRobotView, "robot");
// start the new activity
startActivity(intent, options.toBundle());
}
});
</pre>
<p>Đối vi các dng xem động dùng chung mà bn khi to trong mã ca mình, hãy s dng phương thc
{@link android.view.View#setTransitionName View.setTransitionName()} để quy định một
tên phn t chung trong c hai hot động.</p>
<p>Để đảo ngược hot hình chuyn tiếp cnh khi bn kết thúc hot động th hai, hãy gi phương thc
{@link android.app.Activity#finishAfterTransition Activity.finishAfterTransition()}
thay vì {@link android.app.Activity#finish Activity.finish()}.</p>
<h3>Bt đầu mt hot động bng nhiu phn t chung</h3>
<p>Để to mt hot hình chuyn tiếp cnh gia hai hot động có nhiu hơn mt phn t
chung, hãy định nghĩa các phn t chung trong c hai b trí bng thuc tính <code>android:transitionName</code>
(hoc s dng phương thc {@link android.view.View#setTransitionName View.setTransitionName()}
trong c hai hot động), và to mt đối tượng {@link android.app.ActivityOptions} như sau:</p>
<pre>
ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(this,
Pair.create(view1, "agreedName1"),
Pair.create(view2, "agreedName2"));
</pre>
<h2 id="CurvedMotion">S dng Chuyn động Cong</h2>
<p>Hot hình theo phong cách material design ph thuc vào đường cong làm mu hình ni suy thi gian
và chuyn động không gian. Vi Android 5.0 (API mc 21) tr lên, bn có th định nghĩa đường cong định thi tùy chnh và
mu hình chuyn động cong cho hot hình.</p>
<p>Lp {@link android.view.animation.PathInterpolator} là mt hàm ni suy mi da trên đường cong
Bézier hoc đối tượng {@link android.graphics.Path}. Hàm ni suy này quy định mt đường cong chuyn động
trong mt hình vuông 1x1, vi các đim neo ti (0,0) và (1,1) cùng các đim kim soát được quy định bng cách s dng
các tham đối ca hàm dng. Bn cũng có th định nghĩa mt hàm ni suy đường dn dưới dng tài nguyên XML:</p>
<pre>
&lt;pathInterpolator xmlns:android="http://schemas.android.com/apk/res/android"
android:controlX1="0.4"
android:controlY1="0"
android:controlX2="1"
android:controlY2="1"/>
</pre>
<p>H thng cung cp tài nguyên XML cho ba đường cong cơ bn trong đặc t
material design:</p>
<ul>
<li><code>&#64;interpolator/fast_out_linear_in.xml</code></li>
<li><code>&#64;interpolator/fast_out_slow_in.xml</code></li>
<li><code>&#64;interpolator/linear_out_slow_in.xml</code></li>
</ul>
<p>Bn có th chuyn mt đối tượng {@link android.view.animation.PathInterpolator} ti phương thc {@link
android.animation.Animator#setInterpolator Animator.setInterpolator()}.</p>
<p>Lp {@link android.animation.ObjectAnimator} có các hàm dng mi cho phép bn to hiu ng hot hình
cho các ta độ dc theo mt đường dn bng hai hoc nhiu thuc tính đồng thi. Ví dụ, trình to hot hình sau
s dng mt đối tượng {@link android.graphics.Path} để to hiu ng hot hình cho thuc tính X và Y ca mt dng xem:</p>
<pre>
ObjectAnimator mAnimator;
mAnimator = ObjectAnimator.ofFloat(view, View.X, View.Y, path);
...
mAnimator.start();
</pre>
<h2 id="ViewState">To Hiu ng Hot hình Thay đổi Trng thái Xem</h2>
<p>Lp {@link android.animation.StateListAnimator} cho phép bn định nghĩa trình to hot hình để chy khi
trng thái ca dng xem thay đổi. Ví d sau cho biết cách định nghĩa mt {@link
android.animation.StateListAnimator} dưới dng tài nguyên XML:</p>
<pre>
&lt;!-- animate the translationZ property of a view when pressed -->
&lt;selector xmlns:android="http://schemas.android.com/apk/res/android">
&lt;item android:state_pressed="true">
&lt;set>
&lt;objectAnimator android:propertyName="translationZ"
android:duration="@android:integer/config_shortAnimTime"
android:valueTo="2dp"
android:valueType="floatType"/>
&lt;!-- you could have other objectAnimator elements
here for "x" and "y", or other properties -->
&lt;/set>
&lt;/item>
&lt;item android:state_enabled="true"
android:state_pressed="false"
android:state_focused="true">
&lt;set>
&lt;objectAnimator android:propertyName="translationZ"
android:duration="100"
android:valueTo="0"
android:valueType="floatType"/>
&lt;/set>
&lt;/item>
&lt;/selector>
</pre>
<p>Để gn kèm hot hình trng thái dng xem tùy chnh vào mt dng xem, hãy định nghĩa mt trình to hot hình bng cách s dng phn t
<code>selector</code> trong mt tp tài nguyên XML như trong ví d này, và gán nó cho dng xem
ca bn bng thuc tính <code>android:stateListAnimator</code>. Để gán mt trình to hot hình danh sách trng thái
cho mt dng xem trong mã ca bn, hãy s dng phương thc {@link android.animation.AnimatorInflater#loadStateListAnimator
AnimationInflater.loadStateListAnimator()} và gán trình to hot hình cho dng xem ca bn bng phương thc
{@link android.view.View#setStateListAnimator View.setStateListAnimator()}.</p>
<p>Khi ch đề ca bn m rng ra ch đề material, các nút s có hot hình Z theo mc định. Để tránh hành vi
này trong nút ca bn, hãy đặt thuc tính <code>android:stateListAnimator</code> thành
<code>@null</code>.</p>
<p>Lp {@link android.graphics.drawable.AnimatedStateListDrawable} cho phép bn to các ni dung v được
để hin th hot hình gia các thay đổi trng thái ca dng xem được liên kết. Mt s widget h thng trong
Android 5.0 s dng nhng hot hình này theo mc định. Ví d sau cho biết cách
cách định nghĩa {@link android.graphics.drawable.AnimatedStateListDrawable} dưới dng tài nguyên XML:</p>
<pre>
&lt;!-- res/drawable/myanimstatedrawable.xml -->
&lt;animated-selector
xmlns:android="http://schemas.android.com/apk/res/android">
&lt;!-- provide a different drawable for each state-->
&lt;item android:id="@+id/pressed" android:drawable="@drawable/drawableP"
android:state_pressed="true"/>
&lt;item android:id="@+id/focused" android:drawable="@drawable/drawableF"
android:state_focused="true"/>
&lt;item android:id="@id/default"
android:drawable="@drawable/drawableD"/>
&lt;!-- specify a transition -->
&lt;transition android:fromId="@+id/default" android:toId="@+id/pressed">
&lt;animation-list>
&lt;item android:duration="15" android:drawable="@drawable/dt1"/>
&lt;item android:duration="15" android:drawable="@drawable/dt2"/>
...
&lt;/animation-list>
&lt;/transition>
...
&lt;/animated-selector>
</pre>
<h2 id="AnimVector">To Hiu ng Hot hình Ni dung v được Véc-tơ</h2>
<p><a href="{@docRoot}training/material/drawables.html#VectorDrawables">Ni dung v được Véc-tơ</a> s co giãn được
mà không làm mt độ sc nét. Lp {@link android.graphics.drawable.AnimatedVectorDrawable}
cho phép bn to hiu ng hot hình các thuc tính ca ni dung v được véc-tơ.</p>
<p>Thường thì bn định nghĩa ni dung v được véc-tơ hot hình theo ba tp XML:</p>
<ul>
<li>Ni dung v được véc-tơ vi phn t <code>&lt;vector&gt;</code> trong
<code>res/drawable/</code></li>
<li>Ni dung v được véc-tơ hot hình vi phn t <code>&lt;animated-vector&gt;</code> trong
<code>res/drawable/</code></li>
<li>Mt hoc nhiu trình to hot hình đối tượng vi phn t <code>&lt;objectAnimator&gt;</code> trong
<code>res/anim/</code></li>
</ul>
<p>Ni dung v được véc-tơ hot hình có th to hiu ng hot hình các thuc tính ca phn t <code>&lt;group&gt;</code> và
<code>&lt;path&gt;</code>. Phần tử <code>&lt;group&gt;</code> định nghĩa mt b
đường dn hoc nhóm ph và phn t <code>&lt;path&gt;</code> định nghĩa các đường dẫn sẽ được vẽ.</p>
<p>Khi định nghĩa mt ni dung v được véc-tơ mà bn mun to hiu ng hot hình, hãy s dng thuc tính <code>android:name</code>
để gán mt tên duy nht cho các nhóm và đường dn, sao cho bn có th tham chiếu ti chúng t các định nghĩa
trình to hot hình ca mình. Ví dụ:</p>
<pre>
&lt;!-- res/drawable/vectordrawable.xml -->
&lt;vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="64dp"
android:width="64dp"
android:viewportHeight="600"
android:viewportWidth="600">
&lt;group
<strong>android:name="rotationGroup"</strong>
android:pivotX="300.0"
android:pivotY="300.0"
android:rotation="45.0" >
&lt;path
<strong>android:name="v"</strong>
android:fillColor="#000000"
android:pathData="M300,70 l 0,-70 70,70 0,0 -70,70z" />
&lt;/group>
&lt;/vector>
</pre>
<p>Định nghĩa ni dung v được véc-tơ hot hình s tham chiếu ti các nhóm và đường dn trong ni dung v được véc-tơ theo
tên ca chúng:</p>
<pre>
&lt;!-- res/drawable/animvectordrawable.xml -->
&lt;animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/vectordrawable" >
&lt;target
android:name="rotationGroup"
android:animation="@anim/rotation" />
&lt;target
android:name="v"
android:animation="@anim/path_morph" />
&lt;/animated-vector>
</pre>
<p>Định nghĩa hot hình biu din các đối tượng {@link android.animation.ObjectAnimator} hoc {@link
android.animation.AnimatorSet}. Trình to hot hình đầu tiên trong ví d này s xoay nhóm
đối tượng 360 độ:</p>
<pre>
&lt;!-- res/anim/rotation.xml -->
&lt;objectAnimator
android:duration="6000"
android:propertyName="rotation"
android:valueFrom="0"
android:valueTo="360" />
</pre>
<p>Trình to hot hình th hai trong ví d này s đổi dng đường dn ca ni dung v được véc-tơ t hình này sang
hình khác. C hai đường dn đều phi tương thích vi vic đổi dng: chúng phi có cùng s lnh
và cùng s lượng tham s cho tng lnh.</p>
<pre>
&lt;!-- res/anim/path_morph.xml -->
&lt;set xmlns:android="http://schemas.android.com/apk/res/android">
&lt;objectAnimator
android:duration="3000"
android:propertyName="pathData"
android:valueFrom="M300,70 l 0,-70 70,70 0,0 -70,70z"
android:valueTo="M300,70 l 0,-70 70,0 0,140 -70,0 z"
android:valueType="pathType" />
&lt;/set>
</pre>
<p>Để biết thêm thông tin, hãy xem tài liu tham kho API cho {@link
android.graphics.drawable.AnimatedVectorDrawable}.</p>