FragmentTabHost内容填充剩余空间 [英] FragmentTabHost content filling remaining space
问题描述
我一直在尝试在Android上使用标签导航,但我不能设置内容区域正常。
应用程序的布局:
I've been experimenting with tab navigation on android but I can't set up the content area correctly. The layout of the application:
<?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>
而code我在活动中使用:
And the code I used in the activity:
@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);
}
这会产生以下结果:
This generates the following result:
正如你所看到的内容区域重叠的标签。我只是想它是低于他们,填补了这样的剩余空间:
As you can see the content area overlaps the tabs. I would simply like it to be below them and fill up the remaining space like this:
我已经试过包装他们在一个RelativeLayout的标签和应用以下属性,但没有奏效。我TRID使用权重属性没有任何运气也是如此。
I've tried wrapping them in a RelativeLayout tag and applying the below attribute but it didn't work. I trid using the weight attribute without any luck as well.
感谢。
推荐答案
您不需要拥有的FrameLayout的Tabhost里面,当你做,你正在使用的片段和标签内容的同一空间他们自己。
You don't need to have the FrameLayout inside the Tabhost, when you do that you're using the same space for the content of the fragments and the tabs themselves.
只要把TabHost一个垂直的LinearLayout里面,把外面的FrameLayout的TabHost下面。
Just put the TabHost inside a vertical LinearLayout and put the FrameLayout outside, below the TabHost.
就像这样:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v4.app.FragmentTabHost
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"/>
</android.support.v4.app.FragmentTabHost>
<FrameLayout
android:id="@+id/realtabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
这篇关于FragmentTabHost内容填充剩余空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!