FileDocCategorySizeDatePackage
Transition3d.javaAPI DocAndroid 1.5 API6223Wed May 06 22:41:08 BST 2009com.example.android.apis.animation

Transition3d

public class Transition3d extends android.app.Activity implements View.OnClickListener, AdapterView.OnItemClickListener
This sample application shows how to use layout animation and various transformations on views. The result is a 3D transition between a ListView and an ImageView. When the user clicks the list, it flips to show the picture. When the user clicks the picture, it flips to show the list. The animation is made of two smaller animations: the first half rotates the list by 90 degrees on the Y axis and the second half rotates the picture by 90 degrees on the Y axis. When the first half finishes, the list is made invisible and the picture is set visible.

Fields Summary
private android.widget.ListView
mPhotosList
private android.view.ViewGroup
mContainer
private android.widget.ImageView
mImageView
private static final String[]
PHOTOS_NAMES
private static final int[]
PHOTOS_RESOURCES
Constructors Summary
Methods Summary
private voidapplyRotation(int position, float start, float end)
Setup a new 3D rotation on the container view.

param
position the item that was clicked to show a picture, or -1 to show the list
param
start the start angle at which the rotation must begin
param
end the end angle of the rotation

        // Find the center of the container
        final float centerX = mContainer.getWidth() / 2.0f;
        final float centerY = mContainer.getHeight() / 2.0f;

        // Create a new 3D rotation with the supplied parameter
        // The animation listener is used to trigger the next animation
        final Rotate3dAnimation rotation =
                new Rotate3dAnimation(start, end, centerX, centerY, 310.0f, true);
        rotation.setDuration(500);
        rotation.setFillAfter(true);
        rotation.setInterpolator(new AccelerateInterpolator());
        rotation.setAnimationListener(new DisplayNextView(position));

        mContainer.startAnimation(rotation);
    
public voidonClick(android.view.View v)

        applyRotation(-1, 180, 90);
    
protected voidonCreate(android.os.Bundle savedInstanceState)


    
        
        super.onCreate(savedInstanceState);

        setContentView(R.layout.animations_main_screen);

        mPhotosList = (ListView) findViewById(android.R.id.list);
        mImageView = (ImageView) findViewById(R.id.picture);
        mContainer = (ViewGroup) findViewById(R.id.container);

        // Prepare the ListView
        final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, PHOTOS_NAMES);

        mPhotosList.setAdapter(adapter);
        mPhotosList.setOnItemClickListener(this);

        // Prepare the ImageView
        mImageView.setClickable(true);
        mImageView.setFocusable(true);
        mImageView.setOnClickListener(this);

        // Since we are caching large views, we want to keep their cache
        // between each animation
        mContainer.setPersistentDrawingCache(ViewGroup.PERSISTENT_ANIMATION_CACHE);
    
public voidonItemClick(android.widget.AdapterView parent, android.view.View v, int position, long id)

        // Pre-load the image then start the animation
        mImageView.setImageResource(PHOTOS_RESOURCES[position]);
        applyRotation(position, 0, 90);