2012-02-27 3 views
2

레이아웃에서 ViewFlipper를 설정하면 항상 첫 번째 항목부터 아래쪽으로 시작됩니다.ViewFlipper 및 표시 안 함 첫 번째 항목 onCreate

그러나 "onCreate"에서 ViewFlipper의 두 번째 또는 세 번째 항목부터 시작하는 방법이 있습니까?

카운터가 == 2 인 경우 페이지에 < - 2 -> item onCreate가 표시됩니다.

이것은 제 onCreate 및 Flipper입니다.

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.playlist);} 

XML

<ViewFlipper 
    android:id="@+id/flipper" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:inAnimation="@anim/flipin" 
    android:outAnimation="@anim/flipout" >  

    <!-- 1 --> 
<LinearLayout 
    android:id="@+id/one" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical">    
     <ImageView 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:src="@drawable/airongbg"/> 

</LinearLayout> 
    <!-- 2 --> 
<LinearLayout 
    android:id="@+id/two" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical"> 

     <ImageView 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:src="@drawable/hopefalls"/> 
</LinearLayout> 
    <!-- 3 -->  
<LinearLayout 
    android:id="@+id/three" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical"> 

     <ImageView 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:src="@drawable/moon"/> 
</LinearLayout> 

답변

6

사용이

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.playlist); 
    ((ViewFlipper) this.findViewById(R.id.flipper)).setDisplayedChild(1); //1 for 2 Since it accept Ordinal number 
} 
0

먼저 // 다음 ITM 전화

int id ; 
    id=flipper.indexOfChild(ImageView1); 

으로 표시 할 항목의 위치를 ​​가져옵니다 예 :

flipper.setDisplayedChild(id); 

you will be able to set the desired item 
관련 문제