2012-01-12 55 views
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();  
     } 
    }); 

回答

1

尝试使用的ViewFlipper这些方法:

public void removeViewAt (int index) 
public void addView (View child, int index, ViewGroup.LayoutParams params) 

这应该允许你删除你不再需要一定的看法并添加另一个。

+0

谢谢,我设法用这些方法做到这一点,只需在我的xml文件中添加最初的一个,然后添加每次我想要的视图,然后将其删除 – 2012-01-13 02:11:12