我使用TabView作爲活動佈局。不幸的是,我第一次輸入acticity時,TabView同時顯示所有選項卡的內容,從而創建損壞的輸出。TabView混合來自多個選項卡的內容
我的佈局使用ImageView作爲背景,並在其上添加了TabHost。 ScrollView在那裏,因爲一些標籤的內容需要滾動。我沒有爲每個標籤使用單獨的活動。
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">
<ImageView android:layout_width="fill_parent"
android:layout_height="fill_parent" android:src="@drawable/background_claims"
android:scaleType="centerCrop" />
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost" 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="@android:id/tabs"
android:layout_width="fill_parent" android:layout_height="wrap_content" />
<ScrollView android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<LinearLayout android:id="@+id/overview_tab"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="wrap_content">
</LinearLayout>
<LinearLayout android:id="@+id/journey_tab"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
</LinearLayout>
<LinearLayout android:id="@+id/delay_tab"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
</LinearLayout>
<LinearLayout android:id="@+id/personal_tab"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
</LinearLayout>
<LinearLayout android:id="@+id/ticket_tab"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
</LinearLayout>
</FrameLayout>
</ScrollView>
</LinearLayout>
</TabHost>
</FrameLayout>
...其中爲了簡潔起見,我省略了LinearLayouts的內容。
的LinearLayouts被添加作爲活動的構造函數標籤:
tabHost = getTabHost();
tabHost.setOnTabChangedListener(this);
tabHost.addTab(tabHost.newTabSpec(LIST1_TAB_TAG)
.setIndicator(LIST1_TAB_TAG)
.setContent(new TabContentFactory() {
public View createTabContent(String arg0) {
return (LinearLayout) findViewById(R.id.overview_tab);
}
}));
第一個標籤應該是這樣的:
然而,我第一次進入活動看起來像這樣:
您看到的其他內容來自同一活動中的其他選項卡。
當我點擊另一個標籤,然後回到第一個,輸出是固定的(這是我得到第一個截圖)。行爲是一致的,每次發起活動時都會發生。如果這是相關的,我在HD2上使用Android 2.3.7(CM7)。
非常感謝您的幫助!
我剛試過這個。除了明顯隱藏我的背景圖像之外,它似乎並沒有改善。實際上,現在當我進入活動標籤3替換標籤0上的內容。不過謝謝。 – Yiannis