2010-07-04 3 views

ответ

89

Звонок setDisplayedChild(), передача 0 на основе индекса ребенка View Вы хотите отобразить.

19

См. Этот простой полный пример android.widget.ViewFlipper. С его помощью вы можете создавать различные компоновки из XML, а затем переключаться между ними с простым способом, как это: например

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 с раскладками дерева:

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