我知道我的問題是非常基本的,但相信我,我找不到一個可靠的教程,將教我如何在Android編程中一步一步地使用TabHost,爲像我這樣的初學者。如何在使用XML的android編程中創建tabhost並重命名每個選項卡?
我的問題是我在Eclipse中拖動tabhost到我的佈局,並且我在每個linearlayout上插入了一個textview,但是當我將它安裝在手機上時,只有第二個選項卡的textview在應用程序上可見。我不知道是否有一個兼容性問題,但這裏是我的代碼:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android1="http://schemas.android.com/apk/res/android"
android:id="@+id/sel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android1:id="@+id/activityhead"
android1:layout_width="match_parent"
android1:layout_height="74dp"
android1:text="TextView" />
<LinearLayout
android1:layout_width="match_parent"
android1:layout_height="129dp"
android1:orientation="vertical" >
<ImageButton
android1:id="@+id/imageButton1"
android1:layout_width="124dp"
android1:layout_height="match_parent"
android1:scaleType="fitStart"
android1:src="@drawable/button1" />
</LinearLayout>
<TabHost
android1:id="@android:id/tabhost"
android1:layout_width="match_parent"
android1:layout_height="match_parent" >
<LinearLayout
android1:layout_width="match_parent"
android1:layout_height="match_parent"
android1:orientation="vertical" >
<TabWidget
android1:id="@android:id/tabs"
android1:layout_width="match_parent"
android1:layout_height="wrap_content"
>
</TabWidget>
<FrameLayout
android1:id="@android:id/tabcontent"
android1:layout_width="match_parent"
android1:layout_height="match_parent" >
<LinearLayout
android1:id="@+id/tab1"
android1:orientation="vertical"
android1:layout_width="match_parent"
android1:layout_height="match_parent" >
<TextView
android1:id="@+id/textv1"
android1:layout_width="match_parent"
android1:layout_height="80dp"
android1:text="Sample Text 1"
>
</TextView>
</LinearLayout>
<LinearLayout
android1:id="@+id/tab2"
android1:orientation="vertical"
android1:layout_width="match_parent"
android1:layout_height="match_parent" >
<TextView
android1:id="@+id/textv2"
android1:layout_width="match_parent"
android1:layout_height="80dp"
android1:text="Sample Text 2"
>
</TextView>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
而且,我不知道如何在tabhost改變標籤的名稱。
還想用tabhost?移動到設計支持庫的Tablayout。 –