一、Activity切换动画
入口Activity:public class MainActivity extends Activity {
private Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button=(Button) findViewById(R.id.button1);
}
public void takepage(View v){
Intent intent=new Intent(MainActivity.this,OtherActivity.class);
startActivity(intent);
this.overridePendingTransition(R.anim.enteralpha, R.anim.outralpha);
}
}
res/anim文件夹下特效文件:
enteralpha.xml:
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromAlpha="0"
android:toAlpha="1"
android:duration="5000"
>
outalpha.xml:<?xml version="1.0" encoding="utf-8"?>
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromAlpha="1.0"
android:toAlpha="0"
android:duration="5000"
>
二、页面切换特效:
入口ACtivity文件:public class MainActivity extends Activity {
private ViewFlipper vf;
private float startx;
private float endx;
private Animation in_lefttoright;
private Animation in_righttoleft;
private Animation out_lefttoright;
private Animation out_righttoleft;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
vf=(ViewFlipper) findViewById(R.id.vf);
in_lefttoright=AnimationUtils.loadAnimation(this, R.anim.in_lefttoright);
in_righttoleft=AnimationUtils.loadAnimation(this, R.anim.in_righttoleft);
out_lefttoright=AnimationUtils.loadAnimation(this, R.anim.out_lefttoright);
out_righttoleft=AnimationUtils.loadAnimation(this, R.anim.out_righttoleft);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction()==MotionEvent.ACTION_DOWN) {
startx= event.getX();
}else if (event.getAction()==MotionEvent.ACTION_UP) {
endx=event.getX();
if (endx>startx) {
vf.setInAnimation(in_righttoleft);
vf.setOutAnimation(out_lefttoright);
vf.showNext();//显示后一页
}else if (endx
vf.setInAnimation(in_lefttoright);
vf.setOutAnimation(out_righttoleft);
vf.showPrevious();//显示前一页
}
return true;
}
return super.onTouchEvent(event);
}
}
特效文件:
in_lefttoright.xml:<?xml version="1.0" encoding="utf-8"?>
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="-100%p"
android:toXDelta="0"
android:duration="2000"
>
in_righttoleft.xml:<?xml version="1.0" encoding="utf-8"?>
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="100%p"
android:toXDelta="0"
android:duration="2000"
>
out_lefttoright.xml:<?xml version="1.0" encoding="utf-8"?>
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="0"
android:toXDelta="100%p"
android:duration="2000"
>
out_righttoleft.xml:<?xml version="1.0" encoding="utf-8"?>
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="0"
android:toXDelta="-100%p"
android:duration="2000"
>