0

我正在尝试在 TabActivity 中显示 ListActivity,但由于某种原因,ListActivity 根本不会出现。我得到的只是标签下方的空白区域。

标签活动: https : //picasaweb.google.com/FlyingYellow/Misc#5629459368100202146 列表活动:https ://picasaweb.google.com/FlyingYellow/Misc#5629459406832281026

我完全不知道为什么会这样。我四处搜索,只找到有关输入问题的帖子。我什至无法显示我的内容!

TabActivity.onCreate()

 super.onCreate(savedInstanceState);
 setContentView(R.layout.browser);


 Resources res = getResources();
 TabHost tabHost = getTabHost();
 TabHost.TabSpec spec;
 Intent intent;


 intent = new Intent(this, ArtistBrowser.class);

 spec = tabHost.newTabSpec("artists").setIndicator("Artists", res.getDrawable(R.drawable.ic_tab_artists));
 spec.setContent(intent);

 tabHost.addTab(spec);

 intent = new Intent(this, AlbumBrowser.class);
 spec = tabHost.newTabSpec("albums").setIndicator("Albums", res.getDrawable(R.drawable.ic_tab_artists));
 spec.setContent(intent);

 tabHost.addTab(spec);

 intent = new Intent(this, TrackBrowser.class);
 spec = tabHost.newTabSpec("tracks").setIndicator("Tracks", res.getDrawable(R.drawable.ic_tab_artists));
 spec.setContent(intent);

 tabHost.addTab(spec);

 tabHost.setCurrentTab(0);

(我遵循了 Android 文档教程)

/res/layout/browser.xml

<?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="match_parent"
    android:layout_height="match_parent">

  <LinearLayout
      android:orientation="vertical"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:padding="5dp">
    <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />    <--- this was the error
    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="5dp" />
  </LinearLayout>
</TabHost>
4

1 回答 1

1

再一次,我发现我是个白痴。以防万一其他人遇到此错误,我的问题是我不假思索地将 TabWidget 的高度设置为 match_parent。我通过将 TabWidget 和 FrameLayout 设置为不同的颜色来解决这个问题,并看到整个屏幕都是红色的。天哪,我需要更加小心。

于 2011-07-16T03:01:03.097 回答