對於這個工作,你將需要使用一個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