Android 在viewflipper中添加tabhost

Android 在viewflipper中添加tabhost,android,Android,我是这个平台的新手,已经开始喜欢它了。我正在工作 在项目的UI上,使用tabhost显示两个单独的 使用TabActivity类的活动。这样行。 现在我想在等式中添加一个viewflipper。我正在努力 使用addView()方法将tabhost小部件添加到viewflipper。 例如: 主要目的是创建一个包含两个活动的应用程序,所有活动都是选项卡式的。 然后,viewflipper将在这两个活动之间切换。我是 另一种选择是使用xml布局来保存tabhost 并将其包含在视图中。 我现在避免

我是这个平台的新手,已经开始喜欢它了。我正在工作 在项目的UI上,使用tabhost显示两个单独的 使用TabActivity类的活动。这样行。 现在我想在等式中添加一个viewflipper。我正在努力 使用addView()方法将tabhost小部件添加到viewflipper。 例如:

主要目的是创建一个包含两个活动的应用程序,所有活动都是选项卡式的。 然后,viewflipper将在这两个活动之间切换。我是 另一种选择是使用xml布局来保存tabhost 并将其包含在视图中。 我现在避免使用它,因为这意味着我要写代码 这两门课又来了。 要总结所有这些,有没有一种方法可以将tabhost包含在 视图翻转器

谢谢


新手

您应该将其写入XML中,而不是硬编码。它更容易,看起来更好

在这里,我创建了一个tabhost,它包含一个包含2个listview的ViewFlipper和另一个位于other选项卡中的listview

<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+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">

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textColor="#ffffff"
    android:textSize="18sp"
    android:textStyle="bold"
    android:text="@string/title_text"
    android:id="@+id/title"
    android:background="@drawable/shape"
    android:padding="15dp"
    android:gravity="center"
     />

    <FrameLayout android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:padding="15dp"
        >

        <ListView android:id="@+id/listfav" android:layout_width="fill_parent"
            android:layout_height="wrap_content" android:layout_weight="1">
        </ListView>

        <ViewFlipper android:id="@+id/viewflipper" 
                     android:layout_width="fill_parent" 
                     android:layout_height="fill_parent" 
        > 
        <ListView android:id="@+id/listmain" android:layout_width="fill_parent"
            android:layout_height="wrap_content" android:layout_weight="1">
        </ListView>
        <ListView android:id="@+id/listsub" android:layout_width="fill_parent"
            android:layout_height="wrap_content" android:layout_weight="1">
        </ListView>
        </ViewFlipper>

    </FrameLayout>

    <TabWidget android:id="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0"
    />

</LinearLayout>

你就是这样做的

<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+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">

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textColor="#ffffff"
    android:textSize="18sp"
    android:textStyle="bold"
    android:text="@string/title_text"
    android:id="@+id/title"
    android:background="@drawable/shape"
    android:padding="15dp"
    android:gravity="center"
     />

    <FrameLayout android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:padding="15dp"
        >

        <ListView android:id="@+id/listfav" android:layout_width="fill_parent"
            android:layout_height="wrap_content" android:layout_weight="1">
        </ListView>

        <ViewFlipper android:id="@+id/viewflipper" 
                     android:layout_width="fill_parent" 
                     android:layout_height="fill_parent" 
        > 
        <ListView android:id="@+id/listmain" android:layout_width="fill_parent"
            android:layout_height="wrap_content" android:layout_weight="1">
        </ListView>
        <ListView android:id="@+id/listsub" android:layout_width="fill_parent"
            android:layout_height="wrap_content" android:layout_weight="1">
        </ListView>
        </ViewFlipper>

    </FrameLayout>

    <TabWidget android:id="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0"
    />

</LinearLayout>