【发布时间】:2014-07-09 15:39:17
【问题描述】:
我一直在尝试在 android 上使用标签导航,但我无法正确设置内容区域。 应用布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.app.FragmentTabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabhost"
android:tag="tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:tag="linear">
<TabWidget
android:id="@+id/tabs"
android:tag="tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
</TabWidget>
<FrameLayout
android:id="@+id/tabFrameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</RelativeLayout>
</android.support.v4.app.FragmentTabHost>
片段:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/info_drawer_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#e0e0e0">
<FrameLayout
android:id="@+id/info_content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Fragment info"
android:id="@+id/info_textView"
android:layout_gravity="center_horizontal" />
</FrameLayout>
<ListView android:id="@+id/info_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="#111"/>
</android.support.v4.widget.DrawerLayout>
以及我在活动中使用的代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tabHost = (FragmentTabHost)findViewById(R.id.tabhost);
tabHost.setup(this, getSupportFragmentManager(), R.id.tabFrameLayout);
tabHost.addTab(tabHost.newTabSpec("Tab 0").setIndicator("", getResources().getDrawable(R.drawable.ic_launcher)), InfoFragment.class, null);
tabHost.addTab(tabHost.newTabSpec("Tab 1").setIndicator("Tab 1"), HomeFragment.class, null);
tabHost.addTab(tabHost.newTabSpec("Tab 2").setIndicator("", getResources().getDrawable(R.drawable.ic_launcher)), AppsFragment.class, null);
}
这会产生以下结果:
如您所见,内容区域与选项卡重叠。我只是希望它位于它们下方并像这样填充剩余空间:
我尝试将它们包装在 RelativeLayout 标记中并应用以下属性,但它不起作用。我也尝试过使用 weight 属性,但没有任何运气。
谢谢。
【问题讨论】:
标签: android android-layout tabs android-tabs fragment-tab-host