Transition3dpublic class Transition3d extends android.app.Activity implements View.OnClickListener, AdapterView.OnItemClickListenerThis 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 |
Methods Summary |
---|
private void | applyRotation(int position, float start, float end)Setup a new 3D rotation on the container view.
// 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 void | onClick(android.view.View v)
applyRotation(-1, 180, 90);
| protected void | onCreate(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 void | onItemClick(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);
|
|