繁体   English   中英

Android-具有两个Tabwidgets的Tabhost

[英]Android - Tabhost with two tabwidgets

<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" />
    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
    </FrameLayout>
</LinearLayout>

这是我的布局,然后在扩展TabActivity的活动中添加以下五个不同的标签:

    mTabHost = getTabHost();
    mTabHost.addTab(mTabHost.newTabSpec("tab1").setIndicator("tab1").setContent(new Intent().setClass(this, Activity1.class).putExtra("language", language)));
    mTabHost.addTab(mTabHost.newTabSpec("tab2").setIndicator("tab2").setContent(new Intent().setClass(this, Activity2.class).putExtra("language", language)));
    mTabHost.addTab(mTabHost.newTabSpec("tab3").setIndicator("tab3").setContent(new Intent().setClass(this, Activity3.class).putExtra("language", language)));
    mTabHost.addTab(mTabHost.newTabSpec("tab4").setIndicator("tab4").setContent(new Intent().setClass(this, Activity4.class).putExtra("language", language)));
    mTabHost.addTab(mTabHost.newTabSpec("tab5").setIndicator("tab5").setContent(new Intent().setClass(this, Activity5.class).putExtra("language", language)));

我的问题是所有五个选项卡都放在同一行中,但是我想将三个第一个选项卡放在顶部,然后将另外两个选项卡放在第三个选项卡下面。 我该如何实现?

提前致谢。

如果您只是尝试排列标签(如果所有5个标签均未正确显示),那么这就是您所要求的唯一唯一原因(顶部3个标签,下方2个标签),那么您有更好的解决方案来放置TabView在ScrollView中。

例如 :

<?xml version="1.0" encoding="utf-8"?>
<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">
    <HorizontalScrollView android:layout_width="fill_parent"
                          android:layout_height="wrap_content"
                          android:fillViewport="true"
                          android:scrollbars="none">
      <TabWidget android:id="@android:id/tabs"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"/>
    </HorizontalScrollView>
    <FrameLayout android:id="@android:id/tabcontent"
                 android:layout_width="fill_parent"
                 android:layout_height="fill_parent" />
  </LinearLayout>
</TabHost>

Refreence: Android中的滚动标签

希望您正在寻找相同的东西。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM