1つのビューに2つのタップがある、つまり上部タブと下部タブがあるAndroidアプリケーションを作成したいと思います。
下のタブの選択に従って、下のタブのtapcontent部分に新しいタブホスト(上のタブ用)を追加します。しかし、上のタップは上がらず、下のタブにくっつきます。
上部タブの実装は、
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
public class uppertab extends TabActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.upperlayout);
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent = new Intent().setClass(this, recommend_friend_simillar.class);
spec = tabHost.newTabSpec("upper1").setIndicator("Upper1").setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, recommend_friend_new.class);
spec = tabHost.newTabSpec("upper2").setIndicator("Upper2").setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, recommend_friend_favorite.class);
spec = tabHost.newTabSpec("upper3").setIndicator("Upper3").setContent(intent);
tabHost.addTab(spec);
}
}
アッパータップのxmlは、
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/uppertabhost"
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="@+id/uppertabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@+id/uppertabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
下のタブのxmlは、
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TabHost android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget android:id="@android:id/tabs"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<FrameLayout android:id="@android:id/tabcontent"
android:layout_above="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</FrameLayout>
</RelativeLayout>
</TabHost>
</LinearLayout>
結果を以下に示します。
□□□□□□□□□□□□□□□□□□□□□□□□□□
□ □
□ □
□ □
□ □
□ □
□□□□□□□□□□□□□□□□□□□□□□□□□□
□ □ □ □
□upper1 □ upper2 □ upper3□
□□□□□□□□□□□□□□□□□□□□□□□□□□
□ lower1□lower2 □ lower3□
□□□□□□□□□□□□□□□□□□□□□□□□□□
もちろん、上部の3つのタップは天井に固執する必要があります。
□□□□□□□□□□□□□□□□□□□□□□□□□□
□ □ □ □
□upper1 □ upper2 □ upper3□
□□□□□□□□□□□□□□□□□□□□□□□□□□
□ □
□ □
□ □
□ □
□ □
□□□□□□□□□□□□□□□□□□□□□□□□□□
□ lower1□ lower2 □ lower3□
□□□□□□□□□□□□□□□□□□□□□□□□□□
(activitygroupを使用するようにアドバイスを受けましたが、機能しません。)
import android.app.ActivityGroup;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
public class uppertab extends ActivityGroup {
private TabHost tabHost;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.upperlay);
tabHost = (TabHost)findViewById(R.id.friendtabhost);
tabHost.setup(getLocalActivityManager());
tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("tab1").setContent(new Intent(this, tab1.class)));
tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("tab2").setContent(new Intent(this, tab2.class)));
tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator("tab3").setContent(new Intent(this, tab3.class)));
}
}
DDMSはそれを言います
tabHost.setup(getLocalActivityManager());
問題があります。
私に何ができる :(?