2010-07-04 21 views

Antwort

89

Rufen Sie setDisplayedChild() an und übergeben Sie den 0 -basierten Index des untergeordneten Elements View, das angezeigt werden soll.

19

Siehe dieses einfache vollständige Beispiel android.widget.ViewFlipper. Mit ihm können Sie verschiedenes Layout von XML erstellen und wechseln Sie dann unter sie mit einfacher Methode wie folgt:

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-Beispiel mit Baum-Layout:

 <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> 
Verwandte Themen