【发布时间】:2014-07-13 17:32:45
【问题描述】:
如您所见,片段内容“新文本”与选项卡小部件在同一行开始。标签内容很简单:
<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>
还有选项卡布局:
<android.support.v4.app.FragmentTabHost
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@android:id/tabhost">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/white"/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/tab1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"/>
<LinearLayout
android:id="@+id/tab2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"/>
</FrameLayout>
</RelativeLayout>
</android.support.v4.app.FragmentTabHost >
我尝试使用填充,但填充不是很安全,因为选项卡小部件的高度会随着方向的变化而变化。我也试过了
android:layout_alignParentBottom="@android:id/tabs"
在框架布局上,但是这没有效果。
如何在标签小部件/导航下正确定位标签内容?
编辑片段设置:
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);
【问题讨论】:
-
我看不出有什么问题。您能否发布一些代码和片段的完整 XML 布局?