我正在尝试让滑动手势与 android 应用程序中的选项卡布局一起使用。我正在使用的是单个活动,每个选项卡都有不同的视图。我没有将它们包含在 FrameLayout 中,而是将 ViewFlipper 用于我的选项卡内容。我想让左/右滑动手势将活动选项卡将活动选项卡更改为当前选项卡左侧或右侧的选项卡。
在添加项目后在我的第三个列表中滑动时会出现问题。我看到显示第三个列表的行为,但覆盖在我之前所在的列表上。
任何想法为什么会发生这种情况?
我用于切换视图/选项卡的 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>