Android:布局不显示为选项卡内容
我有一些基于布局的选项卡,它们有自己的xml描述,但当我尝试设置选项卡内容时,我得到了这样一个结果: (带文本的白色字段是home.xml布局的一部分)。下面是一些代码:Android:布局不显示为选项卡内容,android,layout,tabs,Android,Layout,Tabs,我有一些基于布局的选项卡,它们有自己的xml描述,但当我尝试设置选项卡内容时,我得到了这样一个结果: (带文本的白色字段是home.xml布局的一部分)。下面是一些代码: TabSpec spec = tabHost.newTabSpec("home").setIndicator("Home").setContent(R.id.LinearLayout_home); tabHost.addTab(spec); main.xml: <?xml version="1.0"
TabSpec spec = tabHost.newTabSpec("home").setIndicator("Home").setContent(R.id.LinearLayout_home);
tabHost.addTab(spec);
main.xml:
<?xml version="1.0" encoding="utf-8"?>
我认为您的问题在于包含tabwidget元素的布局,请尝试向tabwidget容器添加
android:orientation=“vertical”
属性:
<LinearLayout android:id="@+id/LinearLayout_root"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
TabActivity的默认android模板如下所示:
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost"
android:layout_width="match_parent" android:layout_height="match_parent">
<LinearLayout android:orientation="vertical"
android:layout_width="match_parent" android:layout_height="match_parent">
<TabWidget android:id="@android:id/tabs" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_weight="0" />
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="match_parent" android:layout_height="0dip"
android:layout_weight="1"/>
</LinearLayout>
</TabHost>
我想它也应该对你有用。它有用。。
我确实试过了
<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</TabWidget>
但我确实得到了我的要求
<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</TabWidget>
[删除tabhost下方的额外空间]代码看起来正常。可以发布xml布局的内容吗?当然。。(main)(home)下次尝试将所有相关内容直接粘贴到stackoverflow,以便其他用户更容易找到真相:)添加默认android平台实现作为示例。
<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</TabWidget>