对于这个工作,你将需要使用一个ViewFlipper
这里是你如何设置你的main.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/flipper" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:versionCode="1" android:versionName="1.0">
<include android:id="@+id/first" layout="@layout/home_screen" />
<include android:id="@+id/second" layout="@layout/info_screen" />
</ViewFlipper>
两个视图的XML文件是home_screen和info_screen在这种情况下。你可以给他们任何你想要的名字。
在你的代码,你需要把这个在您的onCreate()方法:
flipper = (ViewFlipper) findViewById(R.id.flipper);
此外,你需要下面的onCreate()方法,这些方法。
private Animation inFromRightAnimation() {
Animation inFromRight = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, +1.0f, Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f
);
inFromRight.setDuration(800);
inFromRight.setInterpolator(new AccelerateInterpolator());
return inFromRight;
}
private Animation outToLeftAnimation()
{
Animation outtoLeft = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, -1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f
);
outtoLeft.setDuration(800);
outtoLeft.setInterpolator(new AccelerateInterpolator());
return outtoLeft;
}
private Animation inFromLeftAnimation() {
Animation inFromLeft = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, -1.0f, Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f
);
inFromLeft.setDuration(800);
inFromLeft.setInterpolator(new AccelerateInterpolator());
return inFromLeft;
}
private Animation outToRightAnimation() {
Animation outtoRight = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, +1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f
);
outtoRight.setDuration(800);
outtoRight.setInterpolator(new AccelerateInterpolator());
return outtoRight;
}
而且当你准备好简单地使用
flipper.setInAnimation(inFromRightAnimation());
flipper.setOutAnimation(outToRightAnimation());
flipper.showNext();
有Android中没有“子视图”,至少不会叫这个名字。 – CommonsWare 2010-06-11 16:19:35
你有图像吗? – Jorgesys 2010-06-11 16:25:38
什么?我想单击ListView上的一个项目,然后根据在原始ListView中选择哪一行来创建一个新的ListView。 – Chris 2010-06-11 16:28:52