in_from_left.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator" >
<translate
android:duration="5000"
android:fromXDelta="-100%p"
android:toXDelta="0%p" />
</set>
out_to_right.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator" >
<translate
android:duration="5000"
android:fromXDelta="0%p"
android:toXDelta="100%p" />
</set>
上面两个组合完成向右滑动效果
in_from_right.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator" >
<translate
android:duration="500"
android:fromXDelta="100%p"
android:toXDelta="0%p" />
</set>
out_to_left.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator" >
<translate
android:duration="500"
android:fromXDelta="0%p"
android:toXDelta="-100%p" />
</set>
上面两个组合完成向左滑动效果
下面为应用代码:
LeftRightSlideActivity.java:
package com.example.change;
import android.R.layout;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.Layout;
import android.view.View;
import android.widget.Button;
public class LeftRightSlideActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setClass(LeftRightSlideActivity.this,
SlideSecondActivity.class);
startActivity(intent);
// 设置切换动画,从右边进入,左边退出
overridePendingTransition(R.anim.in_from_right,
R.anim.out_to_left);
}
});
}
}
SlideSecondActivity.java:
package com.example.change;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
public class SlideSecondActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main1);
}
public void click(View v) {
Intent intent = new Intent();
intent.setClass(SlideSecondActivity.this, SlideSecondActivity2.class);
startActivity(intent);
// 设置切换动画,从右边进入,左边退出
overridePendingTransition(R.anim.in_from_right, R.anim.out_to_left);
}
}
SlideSecondActivity2.java:
package com.example.change;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
public class SlideSecondActivity2 extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main2);
}
public void click(View v) {
Intent intent = new Intent();
intent.setClass(SlideSecondActivity2.this, SlideSecondActivity.class);
startActivity(intent);
// 设置切换动画,从左边进入,右边退出
overridePendingTransition(R.anim.in_from_left, R.anim.out_to_right);
}
}