Android的Activity跳转动画各种效果整理


http://www.jb51.net/article/39026.htm


用overridePendingtransition(int inId, int outId)即可实现。inId是下一界面进入效果的xml文件的id,outId是当前界面退出效果的xml文件id。
效果是用xml文件写的,首先要在res文件夹下建立anim文件夹,然后把动画效果xml文件放到里面去。 
下面是放大进入,缩小退出的xml文件: 
zoomin.xml: 

 
 
 
 
 
 
 

zoomout.xml 

 
 
 
 
 
 
 


MainActivity.java: 

 
public class MainActivity extends Activity implements OnClickListener { 
private Button btn1; 
private Button btn2; 
private Button btn3; 
private Button btn4; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.activity_1); 
btn1 = (Button) findViewById(R.id.btn1); 
btn2 = (Button) findViewById(R.id.btn2); 
btn3 = (Button) findViewById(R.id.btn3); 
btn4 = (Button) findViewById(R.id.btn4); 
btn1.setOnClickListener(this); 
btn2.setOnClickListener(this); 
btn3.setOnClickListener(this); 
btn4.setOnClickListener(this); 
} 

@Override 
public void onClick(View v) { 
// TODO Auto-generated method stub 
int version = Integer.valueOf(android.os.Build.VERSION.SDK); 
switch(v.getId()) { 
case R.id.btn1: 
//放大缩小跳转 
startActivity(new Intent(this, OtherActivity.class)); 
if(version > 5 ){ 
overridePendingTransition(R.anim.zoomin, R.anim.zoomout); 
} 
break; 
case R.id.btn2: 
//淡入淡出跳转 
startActivity(new Intent(this, OtherActivity.class)); 
if(version > 5 ){ 
overridePendingTransition(R.anim.alphain, R.anim.alphaout); 
} 
break; 
case R.id.btn3: 
//左向右跳转 
startActivity(new Intent(this, OtherActivity.class)); 
if(version > 5 ){ 
overridePendingTransition(R.anim.move_in_right, R.anim.move_out_right); 
} 
break; 
case R.id.btn4: 
//右向左跳转 
startActivity(new Intent(this, OtherActivity.class)); 
if(version > 5 ){ 
overridePendingTransition(R.anim.move_in_left, R.anim.move_out_left); 
} 
break; 
} 
finish(); 
} 
} 




你可能感兴趣的:(Android,Activity)