Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 5th, 2012  |  syntax: None  |  size: 1.09 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Android: Translate Animation and Relative Layout
  2. public class Animate extends Animation implements AnimationListener {
  3.     public int height,width;
  4.  
  5.     @Override
  6.     public void initialize(int width, int height, int parentWidth,
  7.             int parentHeight) {
  8.         // TODO Auto-generated method stub
  9.         super.initialize(width, height, parentWidth, parentHeight);
  10.         this.width = width;
  11.         this.height = height;
  12.         setDuration(500);
  13.         setFillAfter(true);
  14.         setInterpolator(new LinearInterpolator());
  15.     }
  16.  
  17.     Camera camera = new Camera();
  18.  
  19.     @Override
  20.     protected void applyTransformation(float interpolatedTime, Transformation t) {
  21.         // TODO Auto-generated method stub
  22.         super.applyTransformation(interpolatedTime, t);
  23.  
  24.         Matrix matrix = t.getMatrix();
  25.         camera.save();
  26.  
  27.         camera.getMatrix(matrix);
  28.         matrix.setTranslate(0, (-height * interpolatedTime));
  29.  
  30.         matrix.preTranslate(0, -height);
  31.         camera.restore();
  32.  
  33.     }
  34.        
  35. View v= new View();
  36. // use whatever view you want and set it up
  37. v.startAnimation(new Animate());