Activity之间切换的各种效果(遗憾没有3D的效果)

http://edison-cool911.iteye.com/blog/730320

下面的Demo是我找到的一个觉得用来在程序中进行Activity之间切换的很好的一个例子: 

Java代码   收藏代码
  1. package com.asai.android.demo;  
  2.   
  3. import android.app.Activity;  
  4. import android.content.Intent;  
  5. import android.os.Bundle;  
  6. import android.view.View;  
  7. import android.widget.ArrayAdapter;  
  8. import android.widget.Button;  
  9. import android.widget.Spinner;  
  10.   
  11. public class demoMain extends Activity {  
  12.     private Button btnDemo;  
  13.     private Spinner sprAnim;  
  14.   
  15.     /** Called when the activity is first created. */  
  16.     @Override  
  17.     public void onCreate(Bundle savedInstanceState) {  
  18.         super.onCreate(savedInstanceState);  
  19.         setContentView(R.layout.main);  
  20.           
  21.         btnDemo = (Button) findViewById(R.id.btnDemo);  
  22.         sprAnim = (Spinner) findViewById(R.id.sprAnim);  
  23.         //Spinner的内容适配器  
  24. ArrayAdapter<?> animType = ArrayAdapter.createFromResource(this,  
  25.                 R.array.anim_type, android.R.layout.simple_spinner_item);  
  26.         animType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);  
  27.         sprAnim.setAdapter(animType);  
  28.                 //默认选中第一项  
  29.         sprAnim.setSelection(0);  
  30.         btnDemo.setOnClickListener(new View.OnClickListener() {  
  31.             public void onClick(View view) {  
  32.                 startActivity(new Intent(demoMain.this, demoDetail.class));  
  33.                 switch (sprAnim.getSelectedItemPosition()) {  
  34.                 case 1:  
  35.                 //淡入淡出效果      
  36.   
  37. overridePendingTransition(R.anim.fade, R.anim.hold);  
  38.                     break;  
  39.                 case 2:  
  40.                     overridePendingTransition(R.anim.alpha_rotate,  
  41.                             R.anim.my_alpha_action);  
  42.                     break;  
  43.                 case 3:  
  44.                     overridePendingTransition(R.anim.alpha_scale_rotate,  
  45.                             R.anim.my_alpha_action);  
  46.                     break;  
  47.                 case 4:  
  48.                     overridePendingTransition(  
  49.                             R.anim.alpha_scale_translate_rotate,  
  50.                             R.anim.my_alpha_action);  
  51.                     break;  
  52.                 case 5:  
  53.                     overridePendingTransition(R.anim.alpha_scale_translate,  
  54.                             R.anim.my_alpha_action);  
  55.                     break;  
  56.                 case 6:  
  57.                 //中心放大效果  
  58.   
  59.     overridePendingTransition(R.anim.alpha_scale,  
  60.                             R.anim.my_alpha_action);  
  61.                     break;  
  62.                 case 7:  
  63.                     overridePendingTransition(R.anim.alpha_translate_rotate,  
  64.                             R.anim.my_alpha_action);  
  65.                     break;  
  66.                 case 8:  
  67.                     overridePendingTransition(R.anim.alpha_translate,  
  68.                             R.anim.my_alpha_action);  
  69.                     break;  
  70.                 case 9:  
  71.                     overridePendingTransition(R.anim.my_rotate_action,  
  72.                             R.anim.my_alpha_action);  
  73.                     break;  
  74.                 case 10:  
  75.                     overridePendingTransition(R.anim.my_scale_action,  
  76.                             R.anim.my_alpha_action);  
  77.                     break;  
  78.                 case 11:  
  79.                     overridePendingTransition(R.anim.my_translate_action,  
  80.                             R.anim.my_alpha_action);  
  81.                     break;  
  82.                 case 12:  
  83.                     overridePendingTransition(R.anim.myanimation_simple,  
  84.                             R.anim.my_alpha_action);  
  85.                     break;  
  86.                 case 13:  
  87.                     overridePendingTransition(R.anim.myown_design,  
  88.                             R.anim.my_alpha_action);  
  89.                     break;  
  90.                 case 14:  
  91.                     overridePendingTransition(R.anim.scale_rotate,  
  92.                             R.anim.my_alpha_action);  
  93.                     break;  
  94.                 case 15:  
  95.                     overridePendingTransition(R.anim.scale_translate_rotate,  
  96.                             R.anim.my_alpha_action);  
  97.                     break;  
  98.                 case 16:  
  99.                     overridePendingTransition(R.anim.scale_translate,  
  100.                             R.anim.my_alpha_action);  
  101.                     break;  
  102.                 case 17:  
  103.                     overridePendingTransition(R.anim.translate_rotate,  
  104.                             R.anim.my_alpha_action);  
  105.                     break;  
  106.                 case 18:  
  107.                     overridePendingTransition(R.anim.hyperspace_in,  
  108.                             R.anim.hyperspace_out);  
  109.                     break;  
  110.                 case 19:  
  111.                     overridePendingTransition(R.anim.shake,  
  112.                             R.anim.my_alpha_action);  
  113.                     break;  
  114.                 case 20:  
  115.                     overridePendingTransition(R.anim.push_left_in,  
  116.                             R.anim.push_left_out);  
  117.                     break;  
  118.                 case 21:  
  119.                 //从下方移出效果   overridePendingTransition(R.anim.push_up_in,  
  120.                             R.anim.push_up_out);  
  121.                     break;  
  122.                 case 22:  
  123.                     overridePendingTransition(R.anim.slide_left,  
  124.                             R.anim.slide_right);  
  125.                     break;  
  126.                 case 23:  
  127.                     overridePendingTransition(R.anim.slide_top_to_bottom,  
  128.                             R.anim.my_alpha_action);  
  129.                     break;  
  130.                 case 24:  
  131.                     overridePendingTransition(R.anim.wave_scale,  
  132.                             R.anim.my_alpha_action);  
  133.                     break;  
  134.                 }  
  135.             }  
  136.         });  
  137.     }  
  138. }  


另外一个activity可以自己随便写个,这里还用到了就是arrays.xml作为Spinner的适配器: 

Java代码   收藏代码
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <resources>  
  3.     <string-array name="anim_type">  
  4.         <item>zoom_enter</item>  
  5.         <item>fade</item>  
  6.         <item>alpha_rotate</item>  
  7.         <item>alpha_scale_rotate</item>  
  8.         <item>alpha_scale_translate_rotate</item>  
  9.         <item>alpha_scale_translate</item>  
  10.         <item>alpha_scale</item>  
  11.         <item>alpha_translate_rotate</item>  
  12.         <item>alpha_translate</item>  
  13.         <item>my_rotate_action</item>  
  14.         <item>my_scale_action</item>  
  15.         <item>my_translate_action</item>  
  16.         <item>myanimation_simple</item>  
  17.         <item>myown_design</item>  
  18.         <item>scale_rotate</item>  
  19.         <item>scale_translate_rotate</item>  
  20.         <item>scale_translate</item>  
  21.         <item>translate_rotate</item>  
  22.         <item>hyperspace_in</item>  
  23.         <item>shake</item>  
  24.         <item>push_left_in</item>  
  25.         <item>push_up_in</item>  
  26.         <item>slide_left</item>  
  27.         <item>slide_top_to_bottom</item>  
  28.         <item>wave_scale</item>  
  29.     </string-array>  
  30. </resources>  



其实这个Demo最重要的就是anim中的一些xml动画定义: 
下面我一个一个的来介绍下(我觉得实用性很好的): 
push_up_in.xml: 

Java代码   收藏代码
  1. <set xmlns:android="http://schemas.android.com/apk/res/android">  
  2.     <translate android:fromYDelta="100%p" android:toYDelta="0" android:duration="300"/>  
  3.     <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="300" />  
  4. </set>  


相信这段代码我不用解释应该也看的懂:改变y坐标来实现动画效果; 
相对应的就是: 
push_up_out.xml: 

Java代码   收藏代码
  1. <set xmlns:android="http://schemas.android.com/apk/res/android">  
  2.     <translate android:fromYDelta="0" android:toYDelta="-100%p" android:duration="300"/>  
  3.     <alpha android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="300" />  
  4. </set>  

你可能感兴趣的:(Activity)