2011-01-31 4 views
1

Je suis en train de faire des gestes swipe travaillant avec une mise en page d'onglet dans une application Android. Ce que je travaille avec est une seule activité avec une vue différente pour chaque onglet. Plutôt que de les contenir dans un FrameLayout, j'utilise un ViewFlipper pour mon contenu d'onglet. Je veux faire des gestes de balayage gauche/droite changer les onglets actifs de l'onglet actif à celui à gauche ou à droite de l'actuel.Gesture Android- mise en page de tabulation avec des listes

Le problème se pose quand et à glisser de ma troisième liste après les articles ont été ajoutés. Je vois un comportement où la troisième liste est affichée, mais elle est superposée sur la liste précédente.

Des idées pour lesquelles cela se passe?

Mon code java pour les vues/onglets de commutation:

public void onSwipe(int direction) {  
    switch (direction) {  
     case SimpleGestureFilter.SWIPE_RIGHT : swipeRight(); break; 
     case SimpleGestureFilter.SWIPE_LEFT : swipeLeft(); break; 
    }  
} 

private void swipeLeft() { 

    viewFlipper.setInAnimation(this,R.anim.slide_in_right); 
    viewFlipper.setOutAnimation(this,R.anim.slide_out_left); 
    viewFlipper.showNext(); 
    tabHost.setCurrentTab((tabHost.getCurrentTab()+1) % NUMTABS); 
} 

private void swipeRight() { 

    viewFlipper.setInAnimation(this, android.R.anim.slide_in_left); 
    viewFlipper.setOutAnimation(this,android.R.anim.slide_out_right); 
    viewFlipper.showPrevious(); 
    tabHost.setCurrentTab((tabHost.getCurrentTab()+(NUMTABS-1)) % NUMTABS); //loop around to avoid -1 
} 

Ma mise en page:

<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@android:id/tabhost" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 
<RelativeLayout 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:padding="5dp"> 
    <TabWidget 
     android:id="@android:id/tabs" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" /> 
    <ViewFlipper 
     android:id="@android:id/tabcontent" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@android:id/tabs" 
     android:layout_above="@+id/search_button" 
     android:padding="5dp" >   
     <ListView android:id="@+id/list1" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:choiceMode="multipleChoice" 
      android:layout_alignParentTop="true" 
      android:textFilterEnabled="true"/> 

     <ListView android:id="@+id/list2" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:choiceMode="multipleChoice" 
      android:layout_alignParentTop="true" 
      android:textFilterEnabled="true"/> 


     <ListView android:id="@+id/list3" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentTop="true"/> 


    </ViewFlipper> 
    <Button android:id="@+id/search_button" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignParentBottom="true" 
       android:text="Search" /> 

</RelativeLayout> 

+0

Notez également que ce que je suis en train de mettre en œuvre est très similaire à la façon de travailler des onglets dans la nouvelles et application météo. Une réponse à cette question s'appliquerait également à celui-ci: http://stackoverflow.com/questions/4483623/android-news-and-weather-app-tabs. – brmcmaho

Répondre