[英]Android TabHost inside TabHost's tab
问候我的开发人员。 我正在一个Android项目中工作,其中我正在使用TabHost,并且在第二个选项卡中我想使用另一个TabHost,到目前为止,我已经完成了这一工作,我的主要TabHost XML是
<TabHost
android:id="@+id/homeTabHost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:orientation="vertical">
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--first tab content-->
<include layout="@layout/content_blood_glucose_diary_home" />
<!--second tab content-->
<include layout="@layout/content_blood_glucose_diary_summary" />
<!--3rd tab content-->
<include layout="@layout/content_blood_glucose_diary_activities" />
</FrameLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"></TabWidget>
</LinearLayout>
</LinearLayout>
</TabHost>
我为此的Java代码是
private void loadTabs(int tabhost, String tab1, String tab2, String tab3){
TabHost host = (TabHost)findViewById(tabhost);
host.setup();
loadTab(host, R.id.homeTab1, tab1); //tab 1
loadTab(host, R.id.homeTab2, tab2); //tab 2
loadTab(host, R.id.homeTab3, tab3); //tab 3
}
private void loadTab(TabHost host, int tabid, String tab){
TabHost.TabSpec spec = host.newTabSpec(tab);
spec.setContent(tabid);
spec.setIndicator(tab);
host.addTab(spec);
}
我从onCreate打电话给我
loadTabs(R.id.homeTabHost, "Today", "Summary", "Activity");
到现在为止,一切都很好,但是当在我的摘要xml中添加另一个tabhost时(像这样)
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="1">
<TabHost
android:id="@+id/summaryTabHost"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.8">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<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="match_parent"
android:layout_height="match_parent">
<!--first tab content-->
<LinearLayout
android:id="@+id/summaryTab1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="tab1" />
</LinearLayout>
<!--second tab content-->
<LinearLayout
android:id="@+id/summaryTab2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="tab2" />
</LinearLayout>
<!--3rd tab content-->
<LinearLayout
android:id="@+id/summaryTab3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="tab3" />
</LinearLayout>
<!--4th tab content-->
<LinearLayout
android:id="@+id/summaryTab4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="tab4" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
并在我的java文件中添加
private void loadTabs(int tabhost, String tab1, String tab2, String tab3, String tab4){
TabHost host = (TabHost)findViewById(tabhost);
host.setup();
loadTab(host, R.id.summaryTab1, tab1); //tab 1
loadTab(host, R.id.summaryTab2, tab2); //tab 2
loadTab(host, R.id.summaryTab3, tab3); //tab 3
loadTab(host, R.id.summaryTab4, tab4); //tab 4
}
这在我的oncreate函数中是
loadTabs(R.id.summaryTabHost, "All", "Yearly", "Monthly", "Weekly");
这应该工作...因为它与第一个选项卡托管一个相同..第一个选项卡托管选项卡不显示是。
但是当我在摘要xml内评论第二个tabhost时。事情看起来很正常。
到目前为止,我的诊断是第二个TabHost可能不正确。
任何想法这里可能有什么问题吗??? 任何帮助都被承认!!
TabHost已被贬值,如果您想在选项卡中创建选项卡,则可以在内部片段中轻松使用它,可以使用选项卡布局
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.