是否可以仅在布局 xml 文件中定义选项卡布局?每次我找到 tabhost 教程时,它都只能与一些额外的 java 代码一起使用。
这是我的 test.xml,它不显示任何选项卡:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/linearLayout">
<TextView android:text="@string/app_name" android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/textView1" android:textAppearance="?android:attr/textAppearanceLarge"></TextView>
<TabHost android:id="@android:id/tabhost" android:layout_width="match_parent" android:layout_height="match_parent">
<TabWidget android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@android:id/tabs">
</TabWidget>
<FrameLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@android:id/tabcontent">
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab1">
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="TAB 1"/>
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab2">
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="TAB 2"/>
</LinearLayout>
</FrameLayout>
</TabHost>
</LinearLayout>
这是不可能的,因为TabSpec http://developer.android.com/reference/android/widget/TabHost.TabSpec.html是代表 TabHost 中每个选项卡的 Holder 类。
并且没有指定要放入 xml 布局中的 TabSpec xml 等效标记。
即使通过代码,对于 TabSpec,也必须指定指示符和内容。否则它会抛出
IllegalArgumentException: you must specify a way to create the tab content
or
IllegalArgumentException: you must specify a way to create the tab indicator.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)