O'Reilly logo

Android 3.0 Animations by Alex Shaw

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action—laying out blocks

We are going to add some more blocks to our tower, to make the game more playable. Rather than writing a load of Java calls to add the new blocks, we can use a layout animation to add them all into the scene.

  1. Create a new XML file in res/anim called layout_tower.xml. This will be the layout animation for tower_1 when the game starts.
  2. In this new file, add the following XML:
    <?xml version="1.0" encoding="utf-8"?>
    <layoutAnimation
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:animation="@anim/block_drop"
    android:delay="20%"
    android:animationOrder="reverse" />
    
  3. This is all you need to declare your layout animation!
    • The actual android:animation itself is just a reference to the block_drop animation ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required