在网上看了很多demo 但是自己用起来都报错了,今天纠结了一天 刚才才试出来 现在贴上我自己的布局文件
正在学习FragmentTabHost 的可以参考一下
<?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" >
<FrameLayout
android:id="@+id/realtabcontent" //注意看这两个地方 ,网上的demo都只在外面定义了一个FrameLayout 我使用总是报错,我就在FragmentTabHost 里面再定义一个FrameLayout ID 都是一样的
android:layout_width="match_parent" //居然可以使用了,表示今天都有弄这个 头大了一天 也没明白这是什么原理,先拿着使用吧。
android:layout_height="0dp"
android:layout_weight="1" />
<android.support.v4.app.FragmentTabHost
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<FrameLayout //在FragmentTabHost 中重新定义了FrameLayout ID 不变
android:id="@id/realtabcontent"
android:layout_width="0dp"
android:layout_height="0dp" />
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp" />
</android.support.v4.app.FragmentTabHost>
</LinearLayout>