【问题标题】:Android Vertical tabhostAndroid 垂直标签主机
【发布时间】:2013-03-22 08:47:14
【问题描述】:

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

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

getTabWidget().setOrientation(LinearLayout.VERTICAL);

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

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

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

帮助我制作垂直标签主机。

【问题讨论】:

    标签: android android-tabhost vertical-alignment


    【解决方案1】:

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

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

    例子:

    <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>
    

    【讨论】:

      【解决方案2】:

      您只需将您的标签小部件放置在 XML 文件中的水平 LinearLayout 中:

      <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 文件中的顺序。

      【讨论】:

      • 是否需要那个viewpager和framelayout?
      【解决方案3】:

      更好地使用片段。使用垂直对齐的按钮进行布局,并使用片段在按钮单击时转换页面。 Refer this 了解更多片段。

      【讨论】:

        猜你喜欢
        • 2016-08-04
        • 2011-08-18
        • 2010-11-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-01-17
        • 2023-03-16
        相关资源
        最近更新 更多