Activity之间经典切换动画效果

主要代码:

Java代码

packagecom.iteye.androidtoast;

importjava.util.ArrayList;

importjava.util.List;

importandroid.app.Activity;

importandroid.content.Intent;

importandroid.os.Bundle;

importandroid.view.View;

importandroid.view.View.OnClickListener;

importandroid.widget.ArrayAdapter;

importandroid.widget.Button;

importandroid.widget.Spinner;

publicclassMainActivityextendsActivity {

/** Called when the activity is first created. */

@Override

publicvoidonCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

finalSpinner mAnimSp = (Spinner) findViewById(R.id.animation_sp);

Button mButton=(Button) findViewById(R.id.other_button);

// 通过资源文件获取Spinner填充内容

String[] ls = getResources().getStringArray(R.array.anim_type);

List list =newArrayList();

// 把数组内容填充 到集合

for(inti =0; i < ls.length; i++) {

list.add(ls[i]);

}

ArrayAdapter animType =newArrayAdapter(this,

android.R.layout.simple_spinner_item, list);

animType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

mAnimSp.setAdapter(animType);

mAnimSp.setSelection(0);

mButton.setOnClickListener(newOnClickListener() {

@Override

publicvoidonClick(View v) {

Intent intent =newIntent();

intent.setClass(MainActivity.this, OtherActivity.class);

startActivity(intent);

switch(mAnimSp.getSelectedItemPosition()) {

case0:

/*注意:此方法只能在startActivity和finish方法之后调用。

第一个参数为第一个Activity离开时的动画,第二参数为所进入的Activity的动画效果*/

overridePendingTransition(R.anim.fade, R.anim.hold);

break;

case1:

overridePendingTransition(R.anim.my_scale_action,

R.anim.my_alpha_action);

break;

case2:

overridePendingTransition(R.anim.scale_rotate,

R.anim.my_alpha_action);

break;

case3:

overridePendingTransition(R.anim.scale_translate_rotate,

R.anim.my_alpha_action);

break;

case4:

overridePendingTransition(R.anim.scale_translate,

R.anim.my_alpha_action);

break;

case5:

overridePendingTransition(R.anim.hyperspace_in,

R.anim.hyperspace_out);

break;

case6:

overridePendingTransition(R.anim.push_left_in,

R.anim.push_left_out);

break;

case7:

overridePendingTransition(R.anim.push_up_in,

R.anim.push_up_out);

break;

case8:

overridePendingTransition(R.anim.slide_left,

R.anim.slide_right);

break;

case9:

overridePendingTransition(R.anim.wave_scale,

R.anim.my_alpha_action);

break;

case10:

overridePendingTransition(R.anim.zoom_enter,

R.anim.zoom_exit);

break;

case11:

overridePendingTransition(R.anim.slide_up_in,

R.anim.slide_down_out);

break;

}

}

});

}

}

资源文件太多不贴了自己下载看吧。希望对你能有点用。

摘自:http://www.iteye.com/topic/1116472;

你可能感兴趣的:(android知识)