14.01.2013 Views

Android™ Application Development - Bahar Ali Khan

Android™ Application Development - Bahar Ali Khan

Android™ Application Development - Bahar Ali Khan

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

es/anim/popin.xml<br />

Chapter 11: Advanced Android <strong>Development</strong><br />

<br />

<br />

<br />

res/anim/popinlayout.xml<br />

<br />

Using Layout Animations<br />

Once you’ve defi ned a Layout Animation, you can apply it to a ViewGroup either in code or in the layout<br />

XML resource. In XML this is done using the android:layoutAnimation tag in the layout defi nition,<br />

as shown in the following XML snippet:<br />

android:layoutAnimation=”@anim/popinlayout”<br />

To set a Layout Animation in code, call setLayoutAnimation on the View Group, passing in a reference<br />

to the LayoutAnimation object you want to apply.<br />

In both cases, the Layout Animation will execute once, when the View Group is fi rst laid out. You can<br />

force it to execute again by calling scheduleLayoutAnimation on the ViewGroup object. The animation<br />

will be executed the next time the View Group is laid out.<br />

Layout Animations also support Animation Listeners.<br />

In the following code snippet, a ViewGroup’s animation is re-run with a listener attached to trigger<br />

additional actions once it’s complete:<br />

aViewGroup.setLayoutAnimationListener(new AnimationListener() {<br />

public void onAnimationEnd(Animation _animation) {<br />

// TODO: Actions on animation complete.<br />

}<br />

public void onAnimationRepeat(Animation _animation) {}<br />

public void onAnimationStart(Animation _animation) {}<br />

});<br />

aViewGroup.scheduleLayoutAnimation();<br />

371

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!