主Activity的布局文件xml


xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/widget33" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/back" android:orientation="vertical" > <TextView android:id="@+id/widget34" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <LinearLayout android:id="@+id/widget36" android:layout_width="fill_parent" android:layout_height="40px" android:background="@drawable/bt_group_back" > <Button android:id="@+id/button_Last" android:layout_width="64px" android:layout_height="fill_parent" android:background="@drawable/ic_cmd_last" /> <Button android:id="@+id/button_Replay" android:layout_width="64px" android:layout_height="fill_parent" android:background="@drawable/ic_cmd_replay" /> <Button android:id="@+id/button_Next" android:layout_width="64px" android:layout_height="fill_parent" android:background="@drawable/ic_cmd_next" /> <Button android:id="@+id/button_List" android:layout_width="64px" android:layout_height="fill_parent" android:background="@drawable/ic_cmd_list" /> <Button android:id="@+id/button_Exit" android:layout_width="65sp" android:layout_height="fill_parent" android:background="@drawable/ic_cmd_power" /> LinearLayout> <ImageButton android:id="@+id/Button01" android:layout_width="90sp" android:layout_height="80sp" android:layout_marginLeft="100sp" android:layout_marginTop="80sp" android:background="@drawable/favorite" android:contentDescription="五角星图片" /> LinearLayout>
主Activity


package zyf.myAnimation; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.widget.Button; import android.widget.ImageButton; import android.widget.Toast; public class myAnimation extends Activity implements OnClickListener { private ImageButton button_toTestAnimation; private Button bt_last, bt_replay, bt_next, bt_list, bt_exit; protected Animation animation; private int[] ID; private MenuItem back_Menu, next_Menu, restart_Menu, selsect_Menu, exit_Menu; private final int Back_Menu_ID = Menu.FIRST + 1; private final int Next_Menu_ID = Menu.FIRST + 2; private final int Selsect_Menu_ID = Menu.FIRST + 3; private final int Restart_Menu_ID = Menu.FIRST + 4; private final int Exit_Menu_ID = Menu.FIRST + 5; private int the_Animation_ID = 0; private int i = 0; private int requestCode = 110; private Bundle bundle; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ID = new int[] { R.anim.myanimation_simple, R.anim.my_alpha_action, R.anim.my_scale_action, R.anim.my_translate_action, R.anim.my_rotate_action, R.anim.alpha_scale, R.anim.alpha_translate, R.anim.alpha_rotate, R.anim.scale_translate, R.anim.scale_rotate, R.anim.translate_rotate, R.anim.alpha_scale_translate, R.anim.alpha_scale_rotate, R.anim.alpha_translate_rotate, R.anim.scale_translate_rotate, R.anim.alpha_scale_translate_rotate, R.anim.myown_design }; findMyButton(); myButtonSetListener(); } private void myButtonSetListener() { bt_last.setOnClickListener(this); bt_replay.setOnClickListener(this); bt_next.setOnClickListener(this); bt_list.setOnClickListener(this); bt_exit.setOnClickListener(this); } private void findMyButton() { button_toTestAnimation = (ImageButton) findViewById(R.id.Button01); bt_last = (Button) findViewById(R.id.button_Last); bt_replay = (Button) findViewById(R.id.button_Replay); bt_next = (Button) findViewById(R.id.button_Next); bt_list = (Button) findViewById(R.id.button_List); bt_exit = (Button) findViewById(R.id.button_Exit); } @Override public boolean onCreateOptionsMenu(Menu menu) { back_Menu = menu.add(0, this.Back_Menu_ID, 1, "上一个动画"); next_Menu = menu.add(0, this.Next_Menu_ID, 2, "下一个动画"); restart_Menu = menu.add(0, this.Restart_Menu_ID, 3, "重新播放"); selsect_Menu = menu.add(0, this.Selsect_Menu_ID, 4, "选择动画"); exit_Menu = menu.add(0, this.Exit_Menu_ID, 5, "退出"); back_Menu.setIcon(R.drawable.ic_menu_back); next_Menu.setIcon(R.drawable.ic_menu_next); restart_Menu.setIcon(R.drawable.ic_menu_restart); selsect_Menu.setIcon(R.drawable.ic_menu_select); exit_Menu.setIcon(R.drawable.ic_power); return super.onCreateOptionsMenu(menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == this.Exit_Menu_ID) { finish(); } else if (item.getItemId() == this.Selsect_Menu_ID) { Intent forIntent = new Intent(); forIntent.setClass(myAnimation.this, MYListActivity.class); startActivityForResult(forIntent, requestCode); } else { switch (item.getItemId()) { case Back_Menu_ID: { toLastIndex(); } break; case Next_Menu_ID: { toNextIndex(); } break; default: break; } load_start_Animation(i); } return super.onOptionsItemSelected(item); } private void load_start_Animation(int i) { the_Animation_ID = ID[i]; if (the_Animation_ID != 0) { animation = AnimationUtils.loadAnimation(this, the_Animation_ID); button_toTestAnimation.startAnimation(animation); } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == this.requestCode) { if (resultCode == RESULT_OK) { try { bundle = data.getExtras(); i = bundle.getInt("INDEX"); load_start_Animation(i); } catch (Exception e) { Toast.makeText(this, "ERROR", Toast.LENGTH_LONG).show(); } } else { Toast.makeText(this, "返回取消", Toast.LENGTH_LONG).show(); } } else { Toast.makeText(this, "无返回!", Toast.LENGTH_LONG).show(); } } public void onClick(View v) { if (v.equals(bt_exit)) { finish(); } else if (v.equals(bt_list)) { Intent forIntent = new Intent(); forIntent.setClass(myAnimation.this, MYListActivity.class); startActivityForResult(forIntent, requestCode); } else { switch (v.getId()) { case R.id.button_Last: { toLastIndex(); } break; case R.id.button_Next: { toNextIndex(); } break; default: break; } load_start_Animation(i); } } private void toLastIndex() { --i; if (i < 0) { i = ID.length - 1; } } private void toNextIndex() { ++i; if (i >= ID.length) { i = 0; } } }
ListView布局文件xml


xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <ListView android:id="@+id/ListView01" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/back" /> LinearLayout>
ListView的Activity


package zyf.myAnimation; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView.OnItemSelectedListener; public class MYListActivity extends Activity implements OnItemClickListener, OnItemSelectedListener { private ListView mylist; private ArrayAdapterarrayAdapter; private String[] contentString; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.list_layout); contentString = new String[] { "示例", "透明动画", "伸缩动画", "移动动画", "旋转动画", "透明_伸缩", "透明_移动", "透明_旋转", "伸缩_移动","伸缩_旋转", "移动_旋转", "透明_伸缩_移动", "透明_伸缩_旋转", "透明_移动_旋转", "伸缩_移动_旋转", "透明_伸缩_移动_旋转", "myown_Design" }; arrayAdapter = new ArrayAdapter (this, android.R.layout.simple_list_item_single_choice, contentString); mylist = (ListView) findViewById(R.id.ListView01); mylist.setAdapter(arrayAdapter); mylist.setOnItemClickListener(this); mylist.setOnItemSelectedListener(this); mylist.setChoiceMode(ListView.CHOICE_MODE_SINGLE); } @Override public boolean onCreateOptionsMenu(Menu menu) { // TODO Auto-generated method stub return super.onCreateOptionsMenu(menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { // TODO Auto-generated method stub return super.onOptionsItemSelected(item); } public void onItemClick(AdapterView> arg0, View arg1, int index, long arg3) { // TODO Auto-generated method stub Intent back_intent= new Intent(); Bundle back_Bundle=new Bundle(); back_Bundle.putInt("INDEX", index); back_intent.putExtras(back_Bundle); setResult(RESULT_OK, back_intent); finish(); } public void onItemSelected(AdapterView> arg0, View arg1, int arg2, long arg3) { // TODO Auto-generated method stub setTitle(arrayAdapter.getItem(arg2)); mylist.setItemChecked(arg2, true); } public void onNothingSelected(AdapterView> arg0) { // TODO Auto-generated method stub } }
R.anim.myanimation_simple, "示例"


xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false" > <scale android:duration="700" android:fillAfter="false" android:fromXScale="1.0" android:fromYScale="1.0" android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:pivotX="50%" android:pivotY="50%" android:toXScale="1.4" android:toYScale="0.6" /> <set android:interpolator="@android:anim/decelerate_interpolator" > <scale android:duration="400" android:fillBefore="false" android:fromXScale="1.4" android:fromYScale="0.6" android:pivotX="50%" android:pivotY="50%" android:startOffset="700" android:toXScale="0.0" android:toYScale="0.0" /> <rotate android:duration="400" android:fromDegrees="0" android:pivotX="50%" android:pivotY="50%" android:startOffset="700" android:toDegrees="-45" android:toYScale="0.0" /> set> set>
R.anim.my_alpha_action, "透明动画"


xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <alpha android:duration="3000" android:fromAlpha="0.1" android:toAlpha="1.0" /> set>
R.anim.my_scale_action, "伸缩动画"


xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <scale android:duration="700" android:fillAfter="false" android:fromXScale="0.0" android:fromYScale="0.0" android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:pivotX="50%" android:pivotY="50%" android:toXScale="1.4" android:toYScale="1.4" /> set>
R.anim.my_translate_action, "移动动画"


xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <translate android:duration="2000" android:fromXDelta="30" android:fromYDelta="30" android:toXDelta="-80" android:toYDelta="300" /> set>
R.anim.my_rotate_action, "旋转动画"


xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <rotate android:duration="3000" android:fromDegrees="0" android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:pivotX="50%" android:pivotY="50%" android:toDegrees="+350" /> set>
R.anim.alpha_scale, "透明_伸缩"


xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false" > <alpha android:duration="500" android:fromAlpha="0.0" android:interpolator="@android:res/anim/accelerate_decelerate_interpolator" android:repeatCount="0" android:toAlpha="1.0" > alpha> <scale android:duration="500" android:fromXScale="1.0" android:fromYScale="1.0" android:interpolator="@android:res/anim/accelerate_decelerate_interpolator" android:pivotX="50%" android:pivotY="50%" android:repeatCount="0" android:startOffset="500" android:toXScale="0.5" android:toYScale="1.4" > scale> set>
R.anim.alpha_translate, "透明_移动"


xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false" > <alpha android:duration="2000" android:fromAlpha="0.0" android:interpolator="@android:res/anim/accelerate_decelerate_interpolator" android:repeatCount="0" android:toAlpha="1.0" > alpha> <translate android:duration="2000" android:fromXDelta="30" android:fromYDelta="30" android:toXDelta="-80" android:toYDelta="300" /> set>
R.anim.alpha_rotate, "透明_旋转"


xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false" > <alpha android:duration="3000" android:fromAlpha="0.0" android:interpolator="@android:res/anim/accelerate_decelerate_interpolator" android:repeatCount="0" android:toAlpha="1.0" > alpha> <rotate android:duration="3000" android:fromDegrees="0" android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:pivotX="50%" android:pivotY="50%" android:toDegrees="+350" /> set>
R.anim.scale_translate, "伸缩_移动"


xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false" > <scale android:duration="2000" android:fromXScale="0.0" android:fromYScale="0.0" android:interpolator="@android:res/anim/accelerate_decelerate_interpolator" android:pivotX="50%" android:pivotY="50%" android:repeatCount="0" android:startOffset="300" android:toXScale="1.0" android:toYScale="1.0" > scale> <translate android:duration="2000" android:fromXDelta="30" android:fromYDelta="30" android:toXDelta="-80" android:toYDelta="250" /> set>
R.anim.scale_rotate, "伸缩_旋转"


xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false" > <scale android:duration="3000" android:fromXScale="0.0" android:fromYScale="0.0" android:interpolator="@android:res/anim/accelerate_decelerate_interpolator" android:pivotX="50%" android:pivotY="50%" android:repeatCount="0" android:startOffset="300" android:toXScale="1.0" android:toYScale="1.0" > scale> <rotate android:duration="3000" android:fromDegrees="0" android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:pivotX="50%" android:pivotY="50%" android:toDegrees="+355" /> set>
R.anim.translate_rotate, "移动_旋转"


xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false" > <translate android:duration="3000" android:fromXDelta="120" android:fromYDelta="30" android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:toXDelta="110" android:toYDelta="50" /> <rotate android:duration="5000" android:fromDegrees="0" android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:pivotX="50%" android:pivotY="50%" android:startOffset="800" android:toDegrees="+360" /> set>
R.anim.alpha_scale_translate, "透明_伸缩_移动"


xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false" > <alpha android:duration="3000" android:fromAlpha="0.0" android:interpolator="@android:res/anim/accelerate_decelerate_interpolator" android:toAlpha="1.0" > alpha> <scale android:duration="3000" android:fromXScale="0.0" android:fromYScale="0.0" android:interpolator="@android:res/anim/accelerate_decelerate_interpolator" android:pivotX="50%" android:pivotY="50%" android:toXScale="1.0" android:toYScale="1.0" > scale> <translate android:duration="3000" android:fromXDelta="120" android:fromYDelta="30" android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:toXDelta="30" android:toYDelta="250" /> set>
R.anim.alpha_scale_rotate, "透明_伸缩_旋转"


xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false" > <alpha android:duration="3000" android:fromAlpha="0.0" android:interpolator="@android:res/anim/accelerate_decelerate_interpolator" android:toAlpha="1.0" > alpha> <scale android:duration="3000" android:fromXScale="0.0" android:fromYScale="0.0" android:interpolator="@android:res/anim/accelerate_decelerate_interpolator" android:pivotX="50%" android:pivotY="50%" android:toXScale="1.0" android:toYScale="1.0" > scale> <rotate android:duration="3000" android:fromDegrees="0" android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:pivotX="50%" android:pivotY="50%" android:toDegrees="+355" /> set>
R.anim.alpha_translate_rotate, "透明_移动_旋转"


xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false" > <alpha android:duration="3000" android:fromAlpha="0.0" android:interpolator="@android:res/anim/accelerate_decelerate_interpolator" android:toAlpha="1.0" /> <translate android:duration="3000" android:fromXDelta="120" android:fromYDelta="30" android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:toXDelta="30" android:toYDelta="250" /> <rotate android:duration="5000" android:fromDegrees="0" android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:pivotX="50%" android:pivotY="50%" android:startOffset="800" android:toDegrees="+360" /> set>
R.anim.scale_translate_rotate, "伸缩_移动_旋转"


xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false" > <scale android:duration="3000" android:fromXScale="0.0" android:fromYScale="0.0" android:interpolator="@android:res/anim/accelerate_decelerate_interpolator" android:pivotX="50%" android:pivotY="50%" android:toXScale="1.0" android:toYScale="1.0" > scale> <translate android:duration="3000" android:fromXDelta="120" android:fromYDelta="30" android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:toXDelta="30" android:toYDelta="250" /> <rotate android:duration="3000" android:fromDegrees="0" android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:pivotX="50%" android:pivotY="50%" android:toDegrees="+355" /> set>
R.anim.alpha_scale_translate_rotate, "透明_伸缩_移动_旋转"


xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false" > <alpha android:duration="3000" android:fromAlpha="0.0" android:interpolator="@android:res/anim/accelerate_decelerate_interpolator" android:toAlpha="1.0" > alpha> <scale android:duration="3000" android:fromXScale="0.0" android:fromYScale="0.0" android:interpolator="@android:res/anim/accelerate_decelerate_interpolator" android:pivotX="50%" android:pivotY="50%" android:toXScale="1.0" android:toYScale="1.0" > scale> <translate android:duration="3000" android:fromXDelta="120" android:fromYDelta="30" android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:toXDelta="30" android:toYDelta="250" /> <rotate android:duration="3000" android:fromDegrees="0" android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:pivotX="50%" android:pivotY="50%" android:toDegrees="+360" /> set>
R.anim.myown_design, "myown_Design"


xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false" > <set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false" > <translate android:duration="800" android:fromYDelta="-100" android:interpolator="@android:anim/accelerate_interpolator" android:pivotX="50%" android:pivotY="50%" android:toYDelta="0" > translate> set> <set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false" > <scale android:duration="400" android:fromXScale="1.0" android:fromYScale="1.0" android:interpolator="@android:anim/accelerate_interpolator" android:pivotX="50%" android:pivotY="100%" android:startOffset="790" android:toXScale="1.0" android:toYScale="0.3" > scale> set> <set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false" > <translate android:duration="400" android:fromYDelta="0" android:interpolator="@android:anim/decelerate_interpolator" android:pivotX="50%" android:pivotY="50%" android:startOffset="1190" android:toYDelta="-60" > translate> set> set>
DEMO完整下载路径:http://download.csdn.net/detail/androidsj/5529847