blob: e3a47d6379abacbe68990392cd4cbfd577e11364 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
page.title=Animating Layout Changes
trainingnavtop=true
@jd:body
<div id="tb-wrapper">
<div id="tb">
<h2>This lesson teaches you to:</h2>
<ol>
<li><a href="#views">Create the Layout</a></li>
<li><a href="#add">Add, Update, or Remove Items from the Layout</a></li>
</ol>
<h2>
Try it out
</h2>
<div class="download-box">
<a href="{@docRoot}shareables/training/Animations.zip" class=
"button">Download the sample app</a>
<p class="filename">
Animations.zip
</p>
</div>
</div>
</div>
<p>A layout animation is a pre-loaded animation that the system runs each time you make a change
to the layout configuration. All you need to do is set an attribute in the layout to tell the
Android system to animate these layout changes, and system-default animations are carried out for you.
</p>
<p class="note"><strong>Tip</strong>: If you want to supply custom layout animations,
create a {@link android.animation.LayoutTransition} object and supply it to
the layout with the {@link android.view.ViewGroup#setLayoutTransition setLayoutTransition()}
method.
</p>
Here's what a default layout animation looks like when adding items to a list:
</p>
<div class="framed-galaxynexus-land-span-8">
<video class="play-on-hover" autoplay>
<source src="anim_layout_changes.mp4" type="video/mp4">
<source src="anim_layout_changes.webm" type="video/webm">
<source src="anim_layout_changes.ogv" type="video/ogg">
</video>
</div>
<div class="figure-caption">
Layout animation
<div class="video-instructions"> </div>
</div>
<p>If you want to jump ahead and see a full working example,
<a href="{@docRoot}shareables/training/Animations.zip">download</a> and
run the sample app and select the Crossfade example. See the following files for the
code implementation:</p>
<ol>
<li><code>src/LayoutChangesActivity.java</code></li>
<li><code>layout/activity_layout_changes.xml</code></li>
<li><code>menu/activity_layout_changes.xml</code></li>
</ol>
<h2 id="views">Create the Layout</h2>
<p>In your activity's layout XML file, set the <code>android:animateLayoutChanges</code>
attribute to <code>true</code> for the layout that you want to enable animations for.
For instance:</p>
<pre>
<LinearLayout android:id="@+id/container"
android:animateLayoutChanges="true"
...
/>
</pre>
<h2 id="activity">Add, Update, or Remove Items from the Layout</h2>
<p>
Now, all you need to do is add, remove, or update items in the layout
and the items are animated automatically:
</p>
<pre>
private ViewGroup mContainerView;
...
private void addItem() {
View newView;
...
mContainerView.addView(newView, 0);
}
</pre>
|