当前位置: 代码迷 >> Android >> (转)Android Activity其间切换的各种效果
  详细解决方案

(转)Android Activity其间切换的各种效果

热度:80   发布时间:2016-05-01 18:15:33.0
(转)Android Activity之间切换的各种效果

main.xml布局文件:?

Java代码
  1. <?xml?version="1.0"?encoding="utf-8"?>??
  2. <LinearLayout?xmlns:android="http://schemas.android.com/apk/res/android"??
  3. ????android:orientation="vertical"?android:layout_width="fill_parent"??
  4. ????android:layout_height="wrap_content"?android:id="@+id/contactItems"??
  5. ????android:paddingBottom="5dip"?android:paddingLeft="12dip"??
  6. ????android:paddingTop="5dip"?android:paddingRight="12dip">??
  7. ????<Spinner?android:layout_height="wrap_content"??
  8. ????????android:layout_width="fill_parent"?android:id="@+id/sprAnim"></Spinner>??
  9. ????<Button?android:layout_height="wrap_content"??
  10. ????????android:layout_width="fill_parent"?android:id="@+id/btn_next"??
  11. ????????android:text="@string/next"></Button>??
  12. </LinearLayout>??


next.xml布局文件:?

Java代码??收藏代码
  1. <?xml?version="1.0"?encoding="utf-8"?>??
  2. <LinearLayout?xmlns:android="http://schemas.android.com/apk/res/android"??
  3. ????android:orientation="vertical"?android:layout_width="fill_parent"??
  4. ????android:layout_height="wrap_content"?android:id="@+id/contactItems"??
  5. ????android:paddingBottom="5dip"?android:paddingLeft="12dip"??
  6. ????android:paddingTop="5dip"?android:paddingRight="12dip">??
  7. ????<TextView?android:layout_height="wrap_content"??
  8. ????????android:layout_width="fill_parent"?android:id="@+id/text2"??
  9. ????????android:textSize="20dip"?android:paddingTop="12px"?android:text="@string/text2"??
  10. ????????android:layout_marginLeft="70px">??
  11. ????</TextView>??
  12. ????<EditText?android:layout_height="wrap_content"??
  13. ????????android:layout_width="fill_parent"></EditText>??
  14. </LinearLayout>??


strings.xml:?

Java代码?
  1. <?xml?version="1.0"?encoding="utf-8"?>??
  2. <resources>??
  3. ????<string?name="app_name">丸子联系人</string>??
  4. ????<string?name="contact_title">丸子联系人</string>??
  5. ??????
  6. ????<string?name="text1">IAIAI?测试</string>??
  7. ????<string?name="text2">测试跳转效果</string>??
  8. ????<string?name="next">下一页</string>??
  9. </resources>??


arrays.xml:?

Java代码??收藏代码
  1. <?xml?version="1.0"?encoding="utf-8"?>??
  2. <resources>??
  3. ????<string-array?name="anim_type">??
  4. ????????<item>淡入淡出效果</item>??
  5. ????????<item>放大淡出效果</item>??
  6. ????????<item>转动淡出效果1</item>??
  7. ????????<item>转动淡出效果2</item>??
  8. ????????<item>左上角展开淡出效果</item>??
  9. ????????<item>压缩变小淡出效果</item>??
  10. ????????<item>右往左推出效果</item>??
  11. ????????<item>下往上推出效果</item>??
  12. ????????<item>左右交叉效果</item>??
  13. ????????<item>放大淡出效果</item>??
  14. ????????<item>缩小效果</item>??
  15. ????????<item>上下交错效果</item>??
  16. ????</string-array>??
  17. </resources>??


anim文件夹里的文件就不一一列出来了,你可以从附件里下载整个工程查看里面效果文件。?

下面是两个类文件,?
IaiaiActivity.java类:?

Java代码?
  1. package?com.iaiai.activity;??
  2. ??
  3. import?java.util.ArrayList;??
  4. import?java.util.List;??
  5. ??
  6. import?android.app.Activity;??
  7. import?android.content.Intent;??
  8. import?android.os.Bundle;??
  9. import?android.view.View;??
  10. import?android.view.View.OnClickListener;??
  11. import?android.widget.ArrayAdapter;??
  12. import?android.widget.Button;??
  13. import?android.widget.Spinner;??
  14. ??
  15. /**?
  16. ?*??
  17. ?*?<p>?
  18. ?*?Title:?IaiaiActivity.java?
  19. ?*?</p>?
  20. ?*?<p>?
  21. ?*?</p>?
  22. ?*?<p>?
  23. ?*?</p>?
  24. ?*?<p>?
  25. ?*?Http:?iaiai.iteye.com?
  26. ?*?</p>?
  27. ?*?<p>
  28. ?*?</p>?
  29. ?*/??
  30. public?class?IaiaiActivity?extends?Activity?{??
  31. ??
  32. ????@Override??
  33. ????protected?void?onCreate(Bundle?savedInstanceState)?{??
  34. ????????super.onCreate(savedInstanceState);??
  35. ????????setContentView(R.layout.main);??
  36. ??
  37. ????????final?Spinner?sprAnim?=?(Spinner)?findViewById(R.id.sprAnim);??
  38. ????????//?获取相应对象??
  39. ????????String[]?ls?=?getResources().getStringArray(R.array.anim_type);??
  40. ????????List<String>?list?=?new?ArrayList<String>();??
  41. ????????//?获取XML中定义的数组??
  42. ????????for?(int?i?=?0;?i?<?ls.length;?i++)?{??
  43. ????????????list.add(ls[i]);??
  44. ????????}??
  45. ????????ArrayAdapter<String>?animType?=?new?ArrayAdapter<String>(this,??
  46. ????????????????android.R.layout.simple_spinner_item,?list);??
  47. ????????animType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);??
  48. ????????sprAnim.setAdapter(animType);??
  49. ????????sprAnim.setSelection(0);??
  50. ??
  51. ????????Button?btn?=?(Button)?findViewById(R.id.btn_next);??
  52. ????????btn.setOnClickListener(new?OnClickListener()?{??
  53. ????????????@Override??
  54. ????????????public?void?onClick(View?v)?{??
  55. ????????????????Intent?it?=?new?Intent(IaiaiActivity.this,?NextActivity.class);??
  56. ????????????????startActivityForResult(it,?0);??
  57. ??
  58. ????????????????switch?(sprAnim.getSelectedItemPosition())?{??
  59. ????????????????case?0:??
  60. ????????????????????overridePendingTransition(R.anim.fade,?R.anim.hold);??
  61. ????????????????????break;??
  62. ????????????????case?1:??
  63. ????????????????????overridePendingTransition(R.anim.my_scale_action,??
  64. ????????????????????????????R.anim.my_alpha_action);??
  65. ????????????????????break;??
  66. ????????????????case?2:??
  67. ????????????????????overridePendingTransition(R.anim.scale_rotate,??
  68. ????????????????????????????R.anim.my_alpha_action);??
  69. ????????????????????break;??
  70. ????????????????case?3:??
  71. ????????????????????overridePendingTransition(R.anim.scale_translate_rotate,??
  72. ????????????????????????????R.anim.my_alpha_action);??
  73. ????????????????????break;??
  74. ????????????????case?4:??
  75. ????????????????????overridePendingTransition(R.anim.scale_translate,??
  76. ????????????????????????????R.anim.my_alpha_action);??
  77. ????????????????????break;??
  78. ????????????????case?5:??
  79. ????????????????????overridePendingTransition(R.anim.hyperspace_in,??
  80. ????????????????????????????R.anim.hyperspace_out);??
  81. ????????????????????break;??
  82. ????????????????case?6:??
  83. ????????????????????overridePendingTransition(R.anim.push_left_in,??
  84. ????????????????????????????R.anim.push_left_out);??
  85. ????????????????????break;??
  86. ????????????????case?7:??
  87. ????????????????????overridePendingTransition(R.anim.push_up_in,??
  88. ????????????????????????????R.anim.push_up_out);??
  89. ????????????????????break;??
  90. ????????????????case?8:??
  91. ????????????????????overridePendingTransition(R.anim.slide_left,??
  92. ????????????????????????????R.anim.slide_right);??
  93. ????????????????????break;??
  94. ????????????????case?9:??
  95. ????????????????????overridePendingTransition(R.anim.wave_scale,??
  96. ????????????????????????????R.anim.my_alpha_action);??
  97. ????????????????????break;??
  98. ????????????????case?10:??
  99. ????????????????????overridePendingTransition(R.anim.zoom_enter,??
  100. ????????????????????????????R.anim.zoom_exit);??
  101. ????????????????????break;??
  102. ????????????????case?11:??
  103. ????????????????????overridePendingTransition(R.anim.slide_up_in,??
  104. ????????????????????????????R.anim.slide_down_out);??
  105. ????????????????????break;??
  106. ????????????????}??
  107. ????????????}??
  108. ????????});??
  109. ????}??
  110. }??


NextActivity.java类:?

Java代码
  1. package?com.iaiai.activity;??
  2. ??
  3. import?android.app.Activity;??
  4. import?android.content.Intent;??
  5. import?android.os.Bundle;??
  6. import?android.view.KeyEvent;??
  7. ??
  8. /**?
  9. ?*??
  10. ?*?<p>?
  11. ?*?Title:?NextActivity.java?
  12. ?*?</p>??
  13. [email protected]?
  14. ?*/??
  15. public?class?NextActivity?extends?Activity?{??
  16. ??
  17. ????@Override??
  18. ????protected?void?onCreate(Bundle?savedInstanceState)?{??
  19. ????????super.onCreate(savedInstanceState);??
  20. ????????setContentView(R.layout.next);??
  21. ????}??
  22. ??
  23. ????public?boolean?onKeyDown(int?keyCode,?KeyEvent?event)?{??
  24. ????????if?(keyCode?==?KeyEvent.KEYCODE_BACK?&&?event.getRepeatCount()?==?0)?{??
  25. ????????????Intent?intent?=?new?Intent(NextActivity.this,?IaiaiActivity.class);??
  26. ????????????setResult(RESULT_OK,?intent);??
  27. ????????????finish();??
  28. ????????????overridePendingTransition(R.anim.slide_up_in,?R.anim.slide_down_out);??
  29. ????????????return?false;??
  30. ????????}??
  31. ????????return?false;??
  32. ????}??
  33. ??
  34. }??



运行效果图:?
?
?

  相关解决方案