0
我试图添加Fragement内TabHost布局:TabHost内片段
public class FriendsTabFregment extends Fragment {
private TabHost tab;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.activity_friends, container, false);
tab = (TabHost) view.findViewById(R.activity_friends.tab);
return view;
}
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addNewTab("Friends", BasicFragment.class, savedInstanceState); //Chat Tab
setTabHeight(50);
}
由于某种原因,我得到的选项卡为空。 这是我的XML:
<TabHost android:id="@+activity_friends/tab"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="4">
<LinearLayout
android:orientation="vertical"
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"/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
</TabHost>
</LinearLayout>
任何想法,为什么?
当我没有使用片段时,它是如何工作的,没有问题? –
使用Fragment时,是否用'@ + id /'替换它? –
[这篇文章描述了如何使用带有碎片的TabHost](http://thepseudocoder.wordpress.com/2011/10/04/android-tabs-the-fragment-way/) –