Android的 - Tabhost有两个tabwidgets [英] Android - Tabhost with two tabwidgets
问题描述
< TabHost的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@机器人:ID / tabhost
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT>
<的LinearLayout
机器人:方向=垂直
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT>
< TabWidget
机器人:ID =@机器人:ID /标签
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT/>
<的FrameLayout
机器人:ID =@机器人:ID / tabcontent
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT>
< /&的FrameLayout GT;
< / LinearLayout中>
这是我的布局,然后在我的活动延伸TabActivity我添加了五种不同的标签是这样的:
mTabHost = getTabHost();
mTabHost.addTab(mTabHost.newTabSpec(TAB1)setIndicator(TAB1)setContent(新意图()setClass(这一点,Activity1.class).putExtra(语言,语言))。);
mTabHost.addTab(mTabHost.newTabSpec(TAB2)setIndicator(TAB2)setContent(新意图()setClass(这一点,Activity2.class).putExtra(语言,语言))。);
mTabHost.addTab(mTabHost.newTabSpec(TAB3)setIndicator(TAB3)setContent(新意图()setClass(这一点,Activity3.class).putExtra(语言,语言))。);
mTabHost.addTab(mTabHost.newTabSpec(TAB4)setIndicator(TAB4)setContent(新意图()setClass(这一点,Activity4.class).putExtra(语言,语言))。);
mTabHost.addTab(mTabHost.newTabSpec(tab5)setIndicator(tab5)setContent(新意图()setClass(这一点,Activity5.class).putExtra(语言,语言))。);
我的问题是,所有的五个选项卡被放在一排,但我希望把顶部的三个第一选项卡,然后在下面的三个第一的另外两个标签。我怎样才能做到这一点?
先谢谢了。
如果你只是想整理标签页(如果所有5显示不正常),任何这是唯一一个理由这样做,你问(在顶部3tabs和2片),那么你有更好的解决方案就摆在你的滚动型TabView的。的
例如:
<?XML版本=1.0编码=UTF-8&GT?;
< TabHost的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@机器人:ID / tabhost
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT>
<的LinearLayout机器人:方向=垂直
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT>
< HorizontalScrollView的android:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:fillViewport =真
机器人:滚动条=无>
< TabWidget机器人:ID =@机器人:ID /标签
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT/>
< / HorizontalScrollView>
<的FrameLayout机器人:ID =@机器人:ID / tabcontent
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT/>
< / LinearLayout中>
< / TabHost>
Refrence: Android中 <滚动标签/ p>
希望你正在寻找相同的。
<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>
This is my layout, then in my activity which extends TabActivity I add the five different tabs like this:
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)));
The problem I have is that all the five tabs are put in one row, but I want to put the three first tabs on top and then the two other tabs below the three first. How can I achieve this?
Thanks in advance.
If you are just trying to arrange your tabs(if all 5 are not displaying properly),any this is the only single reason to do as you asked (at top 3tabs and below 2 tabs), then you have better solution to put your TabView in ScrollView.
For example :
<?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>
Refrence : Scrolling Tabs in Android
Hope you are looking for the same.
这篇关于Android的 - Tabhost有两个tabwidgets的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!