1

Android アプリのタブ レイアウトでスワイプ ジェスチャを動作させようとしています。私が取り組んでいるのは、タブごとに異なるビューを持つ単一のアクティビティです。それらを FrameLayout に含めるのではなく、タブのコンテンツに ViewFlipper を使用しています。左/右のスワイプジェスチャで、アクティブなタブを現在のタブの左または右にあるアクティブなタブに変更したいと考えています。

アイテムが追加された後、3 番目のリストをスワイプすると問題が発生します。3 番目のリストが表示される動作が見られますが、以前のリストに重ねて表示されます。

なぜこれが起こっているのですか?

ビュー/タブを切り替えるための私のJavaコード:

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
}

私のレイアウト:

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

4

1 に答える 1

2

これは、Android SDK 互換性ライブラリですぐにサポートされるようになりました: http://android-developers.blogspot.com/2011/08/horizo ​​ntal-view-swiping-with-viewpager.html?m=1

于 2011-09-08T08:07:25.753 に答える