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