2010-07-04 37 views

Trả lời

89

Gọi setDisplayedChild(), chuyển số 0 dựa trên chỉ mục của trẻ View bạn muốn hiển thị.

19

Xem ví dụ hoàn chỉnh đơn giản này là android.widget.ViewFlipper. Với nó, bạn có thể tạo bố cục khác nhau từ xml và sau đó chuyển đổi giữa chúng bằng phương pháp đơn giản như thế này: ví dụ

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 với cách bài trí cây:

 <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> 
Các vấn đề liên quan