Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将android选项卡内容定位在选项卡的正下方?_Android_Android Layout - Fatal编程技术网

如何将android选项卡内容定位在选项卡的正下方?

如何将android选项卡内容定位在选项卡的正下方?,android,android-layout,Android,Android Layout,正如您所看到的,片段内容“newtext”与tab小部件在同一行开始。选项卡的内容很简单: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <T

正如您所看到的,片段内容“newtext”与tab小部件在同一行开始。选项卡的内容很简单:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New Text"
        android:layout_gravity="center_horizontal" />

</LinearLayout>
但是,这对框架布局没有影响

如何在选项卡小部件/导航下正确定位选项卡内容?

编辑片段设置:

mTabHost = (FragmentTabHost)rootView.findViewById(android.R.id.tabhost);
mTabHost.setup(getActivity(), getChildFragmentManager(), android.R.id.tabhost);

mTabHost.addTab(mTabHost.newTabSpec("tab1").setIndicator("Tab 1"),
                SomeFragment.class, null);
mTabHost.addTab(mTabHost.newTabSpec("tab2").setIndicator("Tab 2"),
                SomeFragment.class, null);
编辑 您的问题在FragmentTabHost设置方法中。请参见顶部的示例+安装说明(上下文、FragmentManager、int containerId)方法。


首先,android:layout\u alignParentBottom不使用id作为值,而是使用布尔值(真/假)-它告诉孩子是否应该将其底部边界与父底部边界对齐。您可以将其设置为true,但只有这样才能解决问题。您要查找的属性是下面的android:layout_=“@android:id/tabs”。使用这两个属性意味着tabcontent视图将位于TabWidget(id:@android:id/tabs)的正下方,并将占据整个屏幕的剩余部分,直到父底部边界

    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@android:id/tabs"
        android:layout_alignParentBottom="true"
        >

顺便说一句,请使用“匹配父项”而不是“填充父项”-它的意思相同,但“填充父项”是一个旧的命名,在Froyo(API级别8)中被弃用。更多信息请点击此处:
这里:


如果您对RelativeLayout有问题,请改用LinearLayout:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.app.FragmentTabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@android:id/tabhost">

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

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/white"/>

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

            <LinearLayout
                android:id="@+id/tab1"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"/>

            <LinearLayout
                android:id="@+id/tab2"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"/>

        </FrameLayout>
    </LinearLayout>
</android.support.v4.app.FragmentTabHost>


我刚刚尝试了这个(我遇到了完全相同的问题),但没有成功-选项卡和框架布局仍然重叠。我可以确认这没有任何效果。奇怪。。。我添加了LinearLayout解决方案,这肯定会奏效。不幸的是,在我这方面也会出现同样的结果。(实际上,
LinearLayout
是我第一次尝试的)。你能检查一下层次视图吗?请检查碎片附着的位置。在我看来,如果片段附加在@android:id/tabcontent内的任何位置,就不可能重叠任何内容。你能发布更多的代码吗?例如FragmentTabHost设置?我看这里没有任何错误。您能发布一些代码和片段的完整XML布局吗?
    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@android:id/tabs"
        android:layout_alignParentBottom="true"
        >
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.app.FragmentTabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@android:id/tabhost">

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

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/white"/>

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

            <LinearLayout
                android:id="@+id/tab1"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"/>

            <LinearLayout
                android:id="@+id/tab2"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"/>

        </FrameLayout>
    </LinearLayout>
</android.support.v4.app.FragmentTabHost>