内容实现如题所示功能:
1. slideExample.java
2.main.xml文件
3.push_left_in.xml(anim文件夹中)
4.push_left_out.xml(anim文件夹中)
5.push_right_in.xml(anim文件夹中)
6.push_right_out.xml(anim文件夹中)
资源文件可以自己添加2张即可
1. slideExample.java
package com.example;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;
import android.widget.Button;
public class slideExample extends Activity {
private Button aboutButton, backButton;
private ViewGroup container1, container2;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// audioMa = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
container1 = (ViewGroup) findViewById(R.id.container1);
container2 = (ViewGroup) findViewById(R.id.container2);
showWin1();
}
public void showWin1() {
aboutButton = (Button) findViewById(R.id.about_btn);
aboutButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
container1.setAnimation(AnimationUtils.loadAnimation(
slideExample.this, R.anim.push_left_out));
container2.setVisibility(View.VISIBLE);
container2.setAnimation(AnimationUtils.loadAnimation(
slideExample.this, R.anim.push_right_in));
container1.setVisibility(View.GONE);
showWin2();
}
});
}
public void showWin2() {
backButton = (Button) findViewById(R.id.back_btn);
backButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
container1.setVisibility(View.VISIBLE);
container1.setAnimation(AnimationUtils.loadAnimation(
slideExample.this, R.anim.push_left_in));
container2.setAnimation(AnimationUtils.loadAnimation(
slideExample.this, R.anim.push_right_out));
container2.setVisibility(View.GONE);
showWin1();
}
});
}
}
2.main.xml文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:id="@+id/container">
<RelativeLayout android:layout_width="fill_parent"
android:id="@+id/container1" android:layout_height="fill_parent"
android:visibility="visible">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:background="@drawable/one" />
<Button android:text="i" android:id="@+id/about_btn"
android:textColor="@drawable/red" android:layout_width="40dip"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true" android:layout_marginRight="15dip" />
</RelativeLayout>
<RelativeLayout android:layout_width="fill_parent"
android:background="@drawable/gray" android:id="@+id/container2"
android:visibility="gone" android:layout_height="fill_parent">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:background="@drawable/three" />
<Button android:text="@string/back" android:id="@+id/back_btn"
android:textColor="@drawable/red" android:layout_width="40dip"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true" android:layout_marginRight="15dip" />
</RelativeLayout>
</RelativeLayout>
3.push_left_in.xml(anim文件夹中)
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="-100%p" android:toXDelta="0"
android:duration="1000" />
</set>
4.push_left_out.xml(anim文件夹中)
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="0" android:toXDelta="-100%p"
android:duration="1000" />
</set>
5.push_right_in.xml(anim文件夹中)
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="100%p" android:toXDelta="0"
android:duration="1000" />
</set>
6.push_right_out.xml(anim文件夹中)
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="0" android:toXDelta="100%p"
android:duration="1000" />
</set>
资源文件可以自己添加2张即可