一个简单的Activity平移动画
2018-04-01 本文已影响0人
majorty
分析:
上一页移入动画 (-屏幕宽度,y)------>(0,y)
上一页移出动画 (0,y)-------------->(屏幕宽度,y)
下一页移入动画 (屏幕宽度,y)-------------->(0,y)
下一页移出动画 (0,y)-------------->(-屏幕宽度,y)



代码实现:
pre_in_anim.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- -100%p 负一屏幕的宽度大小值 -->
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="-100%p"
android:toXDelta="0"
android:duration="500">
</translate>
pre_out_anim.xml
<?xml version="1.0" encoding="utf-8"?>
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="0"
android:toXDelta="100%p"
android:duration="500">
</translate>
next_in_anim.xml
<?xml version="1.0" encoding="utf-8"?>
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="100%p"
android:toXDelta="0"
android:duration="500">
</translate>
next_out_anim.xml
<?xml version="1.0" encoding="utf-8"?>
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="0"
android:toXDelta="-100%p"
android:duration="500">
</translate>
在Activity中跳转使用:
public void prePage(View view){
Intent intent = new Intent(getApplicationContext(), Setup2Activity.class);
startActivity(intent);
finish();
overridePendingTransition(R.anim.pre_in_anim, R.anim.pre_out_anim);
}
public void nextPage(View view){
Intent intent = new Intent(getApplicationContext(), Setup4Activity.class);
startActivity(intent);
finish();
}