0

TabHost を作成し、タブを使用して 4 つのアクティビティ インテントを割り当てましたが、これらは問題なく機能しているようです。私の唯一の問題は、タブホスト ビューのフレームレイアウト #tabcontent 内にアクティビティ コンテンツが表示されないことです。

公式のリファレンスに従い、インターネットをスキャンして解決策を探しましたが、何が問題なのかわかりません。

Log.v("Activity", "Reports") は ant に記録されるため、アクティビティを実行します。したがって、ReportsActivity の setContentView() が問題を引き起こしていると推測しています。しかし、私はこれに慣れていないので、本当にわかりません。(発生するエラーはありません)

これは私のタブホストです

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@android:id/tabhost"
    android:background="#FFFFFF">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#FFFFFF">

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0" />

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:padding="5sp"
            android:layout_weight="1" />

    </LinearLayout>

</TabHost>

これは、TabActivity にタブを追加する方法です

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

// Reports tab
intent = new Intent().setClass(this, ReportsActivity.class);
spec = tabHost.newTabSpec("reports")
        .setIndicator(
                res.getText(R.string.reports),
                res.getDrawable(R.drawable.reports))
        .setContent(intent);
tabHost.addTab(spec);

これが私のコンテンツ アクティビティです (R.layout.reports = テキストビューを使用した linearlayout)

public class ReportsActivity extends Activity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.reports);

        Log.v("Activity", "Reports");
    }
}
4

2 に答える 2

0

これは、デフォルトで水平レイアウトになっているLinearLayoutを選択したためです。android:orientation = "vertical"をLinearLayoutタグ内に設定すると、問題が解決するはずです

于 2013-03-06T17:30:48.610 に答える
0

次のように TabSpec を実装してみてください。

intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

spec = tabHost.newTabSpec("reports")
              .setIndicator(
                  res.getText(R.string.reports),
                  res.getDrawable(R.drawable.reports))
              .setContent(intent);
于 2012-01-02T10:52:56.333 に答える