小编Jim*_* Ng的帖子

Android的; 切换标签时片段重叠

首先,谢谢大家这个伟大的社区.

我试图遵循支持演示示例代码来实现选项卡式片段接口.

顶级,我正在尝试实现两个选项卡,将单个片段与每个选项卡关联,并在相应选择每个选项卡时显示片段.

目前,我有两个问题(但我相信它们是相关的......)

1)每个标签的片段彼此重叠.这可能与不正确的片段附加/分离有关.

2)在某处创建了第三个神秘片段,并与其他片段重叠


在模拟器(和物理设备)上,您可以看到在选择任一选项卡时有两个片段重叠

当选择tab1时,片段1和未知片段重叠.

当选择tab2时,片段1和片段2重叠.


链接到屏幕截图(上传照片的声誉不够......)

(tab1重叠)http://s8.postimg.org/kv81yz745/tab1_overlapping.png

(tab2重叠)http://s8.postimg.org/3tf7wvs91/tab2_overlapping.png


在这里,为了演示/清晰的目的,我将每个片段中的文本分开.

这些屏幕截图的链接位于我的评论/回复中.(没有足够的声誉来上传超过2个链接...)

活动布局(fragment_tabs.xml)

<TabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TabWidget
        android:id="@android:id/tabs"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0"/>

    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_weight="0"/>

    <FrameLayout
        android:id="@+id/realtabcontent"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"/>

</LinearLayout>
</TabHost>
Run Code Online (Sandbox Code Playgroud)

源代码

public class TabbedInfoHome extends SherlockFragmentActivity {

TabHost mTabHost;
TabManager mTabManager;

static String tag1name = "simple1";
static String tag2name = "simple2";

static String tab1string = "You are looking at fragment 1"; …
Run Code Online (Sandbox Code Playgroud)

tabs android android-fragments

7
推荐指数
1
解决办法
8325
查看次数

标签 统计

android ×1

android-fragments ×1

tabs ×1