【发布时间】:2010-04-26 13:28:29
【问题描述】:
我一直在关注 Google 提供的 Tab 示例。我正在尝试使用提供的 XML 布局来设置选项卡布局。
我使用这个 XML 布局@http://developer.android.com/guide/tutorials/views/hello-tabwidget.html
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<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">
<TextView
android:id="@+id/textview1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is a tab" />
<TextView
android:id="@+id/textview2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is another tab" />
<TextView
android:id="@+id/textview3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is a third tab" />
</FrameLayout>
</LinearLayout>
</TabHost>
当我在 Eclipse 布局设计器中切换“布局”选项卡时,我的 Eclipse 中会出现 NullPointerException: null 错误。
当我尝试将 TabHost 和 TabWidget 拖放到空的布局文件中时,也会发生这种情况。
我做错了什么?这看起来很简单。
【问题讨论】:
-
示例代码的所有问题都列在here.