【发布时间】:2017-08-24 13:57:19
【问题描述】:
我见过两个这样的问题,但他们没有答案。
有人说:you should build TabHost at Runtime.
我相信这不是答案。那么如果要从代码中初始化,那么XML设计的目的是什么。
所以,我的问题还是一样:
这是一些TabHost的XML设计
<?xml version="1.0" encoding="utf-8"?>
<TabHost
android:id="@+id/tabHost"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal">
<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">
<LinearLayout
android:id="@+id/tab0"
android:orientation="vertical"
android:background="@color/controlDarkDark"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_gravity="center"
android:visibility="visible">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button on Tab0" />
</LinearLayout>>
<LinearLayout
android:id="@+id/tab1"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button on Tab1" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
我简化了结构,但在运行时仍然可以看到屏幕(见图)。而
的查询TabHost tabHost = (TabHost)findViewById(R.id.tabHost);
【问题讨论】: