Activity进行切换的时候可以加入一些炫酷的动画,
实现代码如下:
MainActivity:
package com.example.administrator.swichlayoutdemo;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import com.tandong.swichlayout.BaseEffects;
import com.tandong.swichlayout.SwitchLayout;
public class MainActivity extends Activity {
private Button btn_ok, btn_1, btn_2, btn_3, btn_4, btn_5, btn_6, btn_7,
btn_8, btn_9, btn_10, btn_11, btn_12, btn_13, btn_14;
@Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
// 设置进入Activity的Activity特效动画,同理可拓展为布局动画
SwitchLayout.getSlideFromBottom(this, false,
BaseEffects.getQuickToSlowEffect());
// 三个参数分别为(Activity/View,是否关闭Activity,特效(可为空))
initListener();
}
private void initListener() {
btn_ok.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent in = new Intent(MainActivity.this, SecondActivity.class);
in.putExtra("key", 0);
MainActivity.this.startActivity(in);
}
});
btn_1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent in = new Intent(MainActivity.this, SecondActivity.class);
in.putExtra("key", 1);
MainActivity.this.startActivity(in);
}
});
btn_2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent in = new Intent(MainActivity.this, SecondActivity.class);
in.putExtra("key", 2);
MainActivity.this.startActivity(in);
}
});
btn_3.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent in = new Intent(MainActivity.this, SecondActivity.class);
in.putExtra("key", 3);
MainActivity.this.startActivity(in);
}
});
btn_4.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent in = new Intent(MainActivity.this, SecondActivity.class);
in.putExtra("key", 4);
MainActivity.this.startActivity(in);
}
});
btn_5.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent in = new Intent(MainActivity.this, SecondActivity.class);
in.putExtra("key", 5);
MainActivity.this.startActivity(in);
}
});
btn_6.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent in = new Intent(MainActivity.this, SecondActivity.class);
in.putExtra("key", 6);
MainActivity.this.startActivity(in);
}
});
btn_7.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent in = new Intent(MainActivity.this, SecondActivity.class);
in.putExtra("key", 7);
MainActivity.this.startActivity(in);
}
});
btn_8.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent in = new Intent(MainActivity.this, SecondActivity.class);
in.putExtra("key", 8);
MainActivity.this.startActivity(in);
}
});
btn_9.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent in = new Intent(MainActivity.this, SecondActivity.class);
in.putExtra("key", 9);
MainActivity.this.startActivity(in);
}
});
btn_10.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent in = new Intent(MainActivity.this, SecondActivity.class);
in.putExtra("key", 10);
MainActivity.this.startActivity(in);
}
});
btn_11.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent in = new Intent(MainActivity.this, SecondActivity.class);
in.putExtra("key", 11);
MainActivity.this.startActivity(in);
}
});
btn_12.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent in = new Intent(MainActivity.this, SecondActivity.class);
in.putExtra("key", 12);
MainActivity.this.startActivity(in);
}
});
btn_13.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent in = new Intent(MainActivity.this, SecondActivity.class);
in.putExtra("key", 13);
MainActivity.this.startActivity(in);
}
});
btn_14.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent in = new Intent(MainActivity.this, SecondActivity.class);
in.putExtra("key", 14);
MainActivity.this.startActivity(in);
}
});
}
private void initView() {
btn_ok = (Button) this.findViewById(R.id.btn_ok);
btn_1 = (Button) this.findViewById(R.id.btn_1);
btn_2 = (Button) this.findViewById(R.id.btn_2);
btn_3 = (Button) this.findViewById(R.id.btn_3);
btn_4 = (Button) this.findViewById(R.id.btn_4);
btn_5 = (Button) this.findViewById(R.id.btn_5);
btn_6 = (Button) this.findViewById(R.id.btn_6);
btn_7 = (Button) this.findViewById(R.id.btn_7);
btn_8 = (Button) this.findViewById(R.id.btn_8);
btn_9 = (Button) this.findViewById(R.id.btn_9);
btn_10 = (Button) this.findViewById(R.id.btn_10);
btn_11 = (Button) this.findViewById(R.id.btn_11);
btn_12 = (Button) this.findViewById(R.id.btn_12);
btn_13 = (Button) this.findViewById(R.id.btn_13);
btn_14 = (Button) this.findViewById(R.id.btn_14);
}
}
SecondActivity:
package com.example.administrator.swichlayoutdemo;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.ImageView;
import com.tandong.swichlayout.BaseEffects;
import com.tandong.swichlayout.SwichLayoutInterFace;
import com.tandong.swichlayout.SwitchLayout;
public class SecondActivity extends Activity implements SwichLayoutInterFace {
private Intent intent;
private ImageView iv_back;
private int key = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
initIntent();
// 设置进入Activity的Activity特效动画,同理可拓展为布局动画
setEnterSwichLayout();
}
private void initIntent() {
intent = getIntent();
key = intent.getExtras().getInt("key");
iv_back = (ImageView) this.findViewById(R.id.iv_back);
iv_back.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
setExitSwichLayout();
}
});
}
public boolean onKeyDown(int keyCode, KeyEvent event) {// 按返回键时退出Activity的Activity特效动画
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
setExitSwichLayout();
return true;
}
return super.onKeyDown(keyCode, event);
}
@Override
public void setEnterSwichLayout() {
switch (key) {
case 0:
SwitchLayout.get3DRotateFromLeft(this, false, null);
// 三个参数分别为(Activity/View,是否关闭Activity,特效(可为空))
break;
case 1:
SwitchLayout.getSlideFromBottom(this, false,
BaseEffects.getMoreSlowEffect());
break;
case 2:
SwitchLayout.getSlideFromTop(this, false,
BaseEffects.getReScrollEffect());
break;
case 3:
SwitchLayout.getSlideFromLeft(this, false,
BaseEffects.getLinearInterEffect());
break;
case 4:
SwitchLayout.getSlideFromRight(this, false, null);
break;
case 5:
SwitchLayout.getFadingIn(this);
break;
case 6:
SwitchLayout.ScaleBig(this, false, null);
break;
case 7:
SwitchLayout.FlipUpDown(this, false,
BaseEffects.getQuickToSlowEffect());
break;
case 8:
SwitchLayout.ScaleBigLeftTop(this, false, null);
break;
case 9:
SwitchLayout.getShakeMode(this, false, null);
break;
case 10:
SwitchLayout.RotateLeftCenterIn(this, false, null);
break;
case 11:
SwitchLayout.RotateLeftTopIn(this, false, null);
break;
case 12:
SwitchLayout.RotateCenterIn(this, false, null);
break;
case 13:
SwitchLayout.ScaleToBigHorizontalIn(this, false, null);
break;
case 14:
SwitchLayout.ScaleToBigVerticalIn(this, false, null);
break;
default:
break;
}
}
@Override
public void setExitSwichLayout() {
switch (key) {
case 0:
SwitchLayout.get3DRotateFromRight(this, true, null);
break;
case 1:
SwitchLayout.getSlideToBottom(this, true,
BaseEffects.getMoreSlowEffect());
break;
case 2:
SwitchLayout.getSlideToTop(this, true,
BaseEffects.getReScrollEffect());
break;
case 3:
SwitchLayout.getSlideToLeft(this, true,
BaseEffects.getLinearInterEffect());
break;
case 4:
SwitchLayout.getSlideToRight(this, true, null);
break;
case 5:
SwitchLayout.getFadingOut(this, true);
break;
case 6:
SwitchLayout.ScaleSmall(this, true, null);
break;
case 7:
SwitchLayout.FlipUpDown(this, true,
BaseEffects.getQuickToSlowEffect());
break;
case 8:
SwitchLayout.ScaleSmallLeftTop(this, true, null);
break;
case 9:
SwitchLayout.getShakeMode(this, true, null);
break;
case 10:
SwitchLayout.RotateLeftCenterOut(this, true, null);
break;
case 11:
SwitchLayout.RotateLeftTopOut(this, true, null);
break;
case 12:
SwitchLayout.RotateCenterOut(this, true, null);
break;
case 13:
SwitchLayout.ScaleToBigHorizontalOut(this, true, null);
break;
case 14:
SwitchLayout.ScaleToBigVerticalOut(this, true, null);
break;
default:
break;
}
}
}
其中强大的动画效果依赖于动画库SwitchLayout1.0.jar包