0

フレームワークの一部として、他の開発者が使用するテンプレート/BaseActivity クラスを作成しようとしています。

クラスを TabActivity で拡張すると、xml は次のようになります/

<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="fill_parent" android:layout_height="fill_parent">
        <View android:layout_width="fill_parent" android:layout_height="0dip"
            android:background="#000" />
        <TabWidget android:id="@android:id/tabs"
            android:layout_width="fill_parent" android:layout_height="wrap_content"
            android:layout_marginLeft="0dip" android:layout_marginRight="0dip" />
        <View android:layout_width="fill_parent" android:layout_height="2dip"
            android:background="#696969" />
        <View android:layout_width="fill_parent" android:layout_height="1dip"
            android:background="#fff" />
        <FrameLayout android:id="@android:id/tabcontent"
            android:layout_width="fill_parent" android:layout_height="fill_parent" />
    </LinearLayout>
</TabHost>

他のプロジェクトで拡張してこのアクティビティを使用すると、android.R.id.tabhost を取得できず、これが必要であるというエラーが表示されます。

これは、getTabHost() または findViewById() の両方のシナリオを呼び出しても発生します。

注意:タブでビューを使用するために、TabActivityを拡張せずにこれを試しました。それは正常に動作します。しかし、アクティビティをタブ コンテンツとして使用したいと考えています。

これは、ライブラリ プロジェクトにして含める場合の問題だと思います。

さらに説明が必要な場合、またはいくつかの回避策を知っている場合は、お知らせください。

4

1 に答える 1

2

私はその問題を回避しました。ユーザーが現在のアクティビティインスタンスをtemplateLibraryに渡す必要があるライブラリクラスを提供しました。

Conetntをandroidタブを含むレイアウトファイルの1つとして設定します。次に、タブホストを取得します。

これについてもっと詳しく知りたい人がいたら教えてください。ユーザーにレイアウトを提供するフレームワークを開発している場合。

于 2011-02-18T04:03:03.680 に答える