0
我想要完成的是有一個三個按鈕的主屏幕,並取決於哪個按鈕你按下相應的視圖從右側滑入。我已經使用ViewFlipper
並使用ViewFlipper.showNext()
我可以在下一個視圖中滑動。我希望能夠更改下一個視圖,以便可以使視圖對應於按鈕。改變哪個視圖旁邊要顯示在ViewFlipper
我試圖使用ViewFlipper.add()
和ViewFlipper.remove()
來實現這一目標,但無濟於事。有人可以告訴我我要去哪裏嗎?提前致謝。
下面是我的代碼爲我的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" >
<include
android:id="@+id/main"
layout="@layout/first_view" />
//Do I need these below?
<include
android:id="@+id/first"
layout="@layout/more_info_1" />
<include
android:id="@+id/second"
layout="@layout/more_info_2" />
<include
android:id="@+id/third"
layout="@layout/more_info_3" />
</ViewFlipper>
這裏是我的onCreate()
方法:
flipper = (ViewFlipper) findViewById(R.id.flipper);
Button moreInfo1 = (Button) findViewById(R.id.moreinfobutton1);
Button moreInfo2 = (Button) findViewById(R.id.moreinfobutton2);
Button moreInfo3 = (Button) findViewById(R.id.moreinfobutton3);
Button backButton1 = (Button) findViewById(R.id.backbutton1);
Button backButton2 = (Button) findViewById(R.id.backbutton2);
Button backButton3 = (Button) findViewById(R.id.backbutton3);
moreInfo1.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
flipper.setInAnimation(inFromRightAnimation());
flipper.setOutAnimation(outToLeftAnimation());
flipper.showNext();
}
});
moreInfo2.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
flipper.setInAnimation(inFromRightAnimation());
flipper.setOutAnimation(outToLeftAnimation());
//What to put here to change the next View to something else?
flipper.showNext();
}
});
moreInfo3.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
flipper.setInAnimation(inFromRightAnimation());
flipper.setOutAnimation(outToLeftAnimation());
flipper.showNext();
}
});
backButton1.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
flipper.setInAnimation(inFromLeftAnimation());
flipper.setOutAnimation(outToRightAnimation());
flipper.showPrevious();
}
});
backButton2.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
flipper.setInAnimation(inFromLeftAnimation());
flipper.setOutAnimation(outToRightAnimation());
flipper.showPrevious();
}
});
backButton3.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
flipper.setInAnimation(inFromLeftAnimation());
flipper.setOutAnimation(outToRightAnimation());
flipper.showPrevious();
}
});
謝謝,我設法用這些方法做到這一點,只需在我的xml文件中添加最初的一個,然後添加每次我想要的視圖,然後將其刪除 – 2012-01-13 02:11:12