android: slide 滑動動畫效果

edagarli發表於2014-04-11
在網上找的一段滑動動畫效果程式碼

  1. /**  
  2.      * 定義從右側進入的動畫效果  
  3.      * @return  
  4.      */  
  5.     protected Animation inFromRightAnimation() {  
  6.         Animation inFromRight = new TranslateAnimation(  
  7.                 Animation.RELATIVE_TO_PARENT, +1.0f,  
  8.                 Animation.RELATIVE_TO_PARENT, 0.0f,  
  9.                 Animation.RELATIVE_TO_PARENT, 0.0f,  
  10.                 Animation.RELATIVE_TO_PARENT, 0.0f);  
  11.         inFromRight.setDuration(500);  
  12.         inFromRight.setInterpolator(new AccelerateInterpolator());  
  13.         return inFromRight;  
  14.     }  
  15.    
  16.     /**  
  17.      * 定義從左側退出的動畫效果  
  18.      * @return  
  19.      */  
  20.     protected Animation outToLeftAnimation() {  
  21.         Animation outtoLeft = new TranslateAnimation(  
  22.                 Animation.RELATIVE_TO_PARENT, 0.0f,  
  23.                 Animation.RELATIVE_TO_PARENT, -1.0f,  
  24.                 Animation.RELATIVE_TO_PARENT, 0.0f,  
  25.                 Animation.RELATIVE_TO_PARENT, 0.0f);  
  26.         outtoLeft.setDuration(500);  
  27.         outtoLeft.setInterpolator(new AccelerateInterpolator());  
  28.         return outtoLeft;  
  29.     }  
  30.    
  31.     /**  
  32.      * 定義從左側進入的動畫效果  
  33.      * @return  
  34.      */  
  35.     protected Animation inFromLeftAnimation() {  
  36.         Animation inFromLeft = new TranslateAnimation(  
  37.                 Animation.RELATIVE_TO_PARENT, -1.0f,  
  38.                 Animation.RELATIVE_TO_PARENT, 0.0f,  
  39.                 Animation.RELATIVE_TO_PARENT, 0.0f,  
  40.                 Animation.RELATIVE_TO_PARENT, 0.0f);  
  41.         inFromLeft.setDuration(500);  
  42.         inFromLeft.setInterpolator(new AccelerateInterpolator());  
  43.         return inFromLeft;  
  44.     }  
  45.    
  46.     /**  
  47.      * 定義從右側退出時的動畫效果  
  48.      * @return  
  49.      */  
  50.     protected Animation outToRightAnimation() {  
  51.         Animation outtoRight = new TranslateAnimation(  
  52.                 Animation.RELATIVE_TO_PARENT, 0.0f,  
  53.                 Animation.RELATIVE_TO_PARENT, +1.0f,  
  54.                 Animation.RELATIVE_TO_PARENT, 0.0f,  
  55.                 Animation.RELATIVE_TO_PARENT, 0.0f);  
  56.         outtoRight.setDuration(500);  
  57.         outtoRight.setInterpolator(new AccelerateInterpolator());  
  58.         return outtoRight;  
  59.     }

相關文章