gpt4 book ai didi

Android- 支持手势的选项卡布局和列表

转载 作者:行者123 更新时间:2023-11-29 22:29:13 31 4
gpt4 key购买 nike

我正在尝试让滑动手势与 Android 应用程序中的选项卡布局一起使用。我正在处理的是一个 Activity ,每个选项卡都有不同的 View 。我没有将它们包含在 FrameLayout 中,而是为我的选项卡内容使用了 ViewFlipper。我想让左/右滑动手势将 Activity 选项卡更改为当前选项卡左侧或右侧的选项卡。

在我的第三个列表中添加项目后,在来回滑动时出现问题。我看到显示第三个列表的行为,但它覆盖在我之前所在的列表上。

知道为什么会这样吗?

我用于切换 View /选项卡的 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>

最佳答案

关于Android- 支持手势的选项卡布局和列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4851706/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com