Android 滑动显示下一层界面
主要activity:
public class UpPage extends Activity {
private Button upButton;
private Button downButton;
private Animation ani1;
private Animation ani2;
private int status = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_up_page);
upButton = (Button)findViewById(R.id.up_page);
downButton = (Button)findViewById(R.id.down_page);
ani1 = new TranslateAnimation(0,500,0,0);
ani1.setInterpolator(new AccelerateDecelerateInterpolator());
ani1.setDuration(300);
ani1.setFillAfter(true);
ani2 = new TranslateAnimation(500,0,0,0);
ani2.setInterpolator(new AccelerateDecelerateInterpolator());
ani2.setDuration(300);
ani2.setFillAfter(true);
// ani1= AnimationUtils.loadAnimation(this, R.anim.go);
// ani2= AnimationUtils.loadAnimation(this, R.anim.back);
addUpButtonListener();
}
@Override
public booleanonCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds itemsto the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_up_page, menu);
return true;
}
public voidaddUpButtonListener(){
upButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v){
if(status == 0){
upButton.startAnimation(ani1);
status = 1;
}else if(status == 1){
upButton.startAnimation(ani2);
status = 0;
}
}
});
}
}
xml文件:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".UpPage" >
<Button android:id="@+id/down_page"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#f0f"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="downpage" />
<Button android:id="@+id/up_page"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ff0"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="uppage" />
</FrameLayout>
运行效果: