2

我想构建一个垂直标签主机,如下图所示

在此处输入图像描述

我尝试使用以下代码,但选项卡不可见

getTabWidget().setOrientation(LinearLayout.VERTICAL);

是否可以像下面那样实现选项卡主机。如果可能的话,告诉我如何实现下面的选项卡主机。如果有任何内置项目来实现它,如下图所示,还发布链接。(或)是否可以将活动添加到图像视图单击类似于标签栏单击如下

  mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("TAB 1").setContent(R.id.textview1)); 

因为如果可能的话,我将放置图像视图并更改每个项目单击的活动

帮助我制作垂直选项卡主机。

4

3 回答 3

4

您只需将您的选项卡小部件水平放置LinearLayout在 XML 文件中:

<TabHost
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_below="@+id/imageView3" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="horizontal" >

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_weight="0"/>

        <android.support.v4.view.ViewPager
            android:id="@+id/pager"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1" >
        </android.support.v4.view.ViewPager>

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_gravity="center_vertical">
        </TabWidget>

    </LinearLayout>
</TabHost>

这会将选项卡放置在内容的右侧,如果您希望将其放在左侧,则需要重新排列 XML 文件中的顺序。

于 2013-04-01T09:30:35.590 回答
2

更好地使用片段。使用垂直对齐的按钮进行布局,并使用片段在按钮单击时转换页面。请参阅此以了解有关片段的更多信息。

于 2013-04-01T09:24:25.550 回答
0

只是为了补充 Emil Adz 的答案。

当您使用图形工具将控件添加到布局时,这会添加它所需的所有代码,但它会丢失android:orientation="vertical"每个 LinerLyout。

例子:

<LinearLayout
                android:id="@+id/tab1"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                 >
            </LinearLayout>

您必须自己输入

<LinearLayout
                android:id="@+id/tab1"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" >
            </LinearLayout>
于 2013-10-19T00:20:24.790 回答