0

既存の TabHost/TabActivity 内で TabHost を使用したかったのです。そこで、Activity クラスを取り除き、TabHost から継承するビューグループ クラスを実装したいと考えました。ただし、対応する Activity クラスなしで TabHost を使用することはできないようです - TabHost とその内容は、拡張クラスを表示するときに表示されません。

TabHost クラスを使用し、xml から適切な ID (android:id/tabs および android:id/tabcontent) を持つタブとコンテンツ コンテナーを含む線形レイアウトを追加しました。

public class EmitterView : TabHost, TabHost.ITabContentFactory
{
public EmitterView(Context context) :
base(context)
{
Initialize();
}

public EmitterView(Context context, IAttributeSet attrs) :
base(context, attrs)
{
Initialize();
}

private void Initialize()
{
// construct the TAB Host

LayoutInflater inflater = (LayoutInflater)    
this.Context.GetSystemService(Context.LayoutInflaterService);
View view = inflater.Inflate(AndroidFilterEditor.Resource.Layout.EmitterTabHost, null);
this.AddView(view);

this.Setup();

// Create Tabs
TabSpec emitter = this.NewTabSpec("Emitter");
emitter.SetIndicator("Emitter", Resources.GetDrawable(AndroidFilterEditor.Resource.Drawable.ic_tab_artists));
//Intent emitterIntent = new Intent(this.Context, typeof(EmitterActivity));
emitter.SetContent(this);
this.AddTab(emitter);
this.Invalidate();
}

public View CreateTabContent(string tag)
{
EmitterContentView view = new EmitterContentView(this.Context);
return view;
}
}

レイアウト定義:

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp">
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp"/>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>

これが可能かどうか、考えはありますか?これは Android 用のモノなので、コードは明らかに C# です。

4

1 に答える 1

0

ActivityGroup を使用して複数のアクティビティをホストし、それぞれにタブホストを割り当てることができます。複雑になり、奨励されませんが。別のタブホスト内でタブホストの代わりにフラグメントを使用することをお勧めします。

于 2012-07-25T13:22:08.367 に答える