4
我想製作一個Android應用程序,它在一個視圖中有兩個敲擊,即具有較高的選項卡和較低的選項卡。如何在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個水龍頭應堅持ceilling一樣,
□□□□□□□□□□□□□□□□□□□□□□□□□□
□ □ □ □
□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());
有問題。 ?
我能做些什麼:(
你可能想調用你的問題「如何在android中實現**嵌套** TabActivity?」。 (還要注意'TabActivity'的拼寫。) – user634618 2011-03-02 01:32:00