2010-07-04 4 views

Répondre

89

Appelez setDisplayedChild(), en passant l'index 0 de l'enfant View que vous souhaitez afficher.

19

Voir cet exemple complet simple de android.widget.ViewFlipper. Avec elle, vous pouvez créer différents de mise en page XML, puis basculer entre eux avec méthode simple comme ceci:

ViewFlipper viewFlipper = (ViewFlipper) findViewById(R.id.myViewFlipper); 

    // you can switch between next and previous layout and display it 
    viewFlipper.showNext(); 
    viewFlipper.showPrevious(); 

    // or you can switch selecting the layout that you want to display 
    viewFlipper.setDisplayedChild(1); 
    viewFlipper.setDisplayedChild(viewFlipper.indexOfChild(findViewById(R.id.secondLayout) 

Xml exemple avec des configurations d'arbres:

 <ViewFlipper 
      android:id="@+id/myViewFlipper" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" > 

      <LinearLayout 
       android:id="@+id/firstLayout" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:orientation="vertical" > 
       [...] 
      </LinearLayout> 

      <LinearLayout 
       android:id="@+id/secondLayout" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:orientation="vertical" > 
       [...] 
      </LinearLayout> 

      <LinearLayout 
       android:id="@+id/thirdLayout" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:orientation="vertical" > 
       [...] 
      </LinearLayout> 
     </ViewFlipper> 
Questions connexes