Android:在底部的标签

我已经看到了一些这样的喋喋不休,但没有确定。 有没有办法将TabWidget中的标签放在屏幕的底部? 如果是这样,怎么样?

我试过以下,但没有工作:

a)将tabwidget设置在framelayout下方
b)将tabwidget的引力设置为“bottom”

谢谢! llappall

这是最简单,最强大,最具扩展性的解决scheme,可以在屏幕底部显示标签。

  1. 在垂直LinearLayout中,将FrameLayout放在TabWidget的上方
  2. 在FrameLayout和TabWidget上将layout_height设置为wrap_content
  3. 设置FrameLayout的android:layout_weight="1"
  4. 设置TabWidget的android:layout_weight="0" (0是默认的,但为了强调,可读性等)
  5. 设置TabWidget的android:layout_marginBottom="-4dp" (去除底部分隔线)

完整代码:

 <?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" android:padding="5dp"> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="wrap_content" android:padding="5dp" android:layout_weight="1"/> <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="0" android:layout_marginBottom="-4dp"/> </LinearLayout> </TabHost> 

尝试一下;)只要观看FrameLayout(@ id / tabcontent)的内容,因为我不知道它将如何处理滚动的情况…在我的情况下,它的作品,因为我用ListView作为我的标签的内容。 :) 希望能帮助到你。

 <?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"> <RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent"> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_alignParentTop="true" android:layout_above="@android:id/tabs" /> <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" /> </RelativeLayout> </TabHost> 

有一种方法可以删除该行。

1)按照这个教程: android-tabs-with-fragments

2)然后应用Leaudro上面build议的RelativeLayout更改(将布局道具应用于所有FrameLayout)。

您也可以将ImageView添加到项目#1中的tab.xml中,并获得非常类似于标签的iPhone。

这里是我正在工作的一个截图。 我还有一些工作要做,主要是为图标做一个select器,并确保水平分布均匀,但是你明白了。 在我的情况下,我使用片段,但相同的校长应该适用于标准的标签视图。

在这里输入图像说明

不知道它是否适用于所有版本的Android(尤其是那些自定义UI的东西),但我能够通过添加删除底部的灰色条

  android:layout_marginBottom="-3dp" 

到TabWidget XML …

对于所有那些尝试删除tabWidget的分隔线的人来说,这里是一个示例项目(及其相应的教程),这对于自定义选项卡非常有用,因此可以在选项卡处于底部时删除问题。 Eclipse项目: android-custom-tabs ; 原文解释: 博客 ; 希望这有助于。

有两种方式可以在选项卡活动的底部显示选项卡。

  1. 使用相对布局
  2. 使用Layout_weight属性

请检查链接了解更多详情 。

 <?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:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="0dip" android:layout_weight="1" /> <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="0" android:background="#252a31" android:tabStripEnabled="false" > </TabWidget> </LinearLayout> </TabHost> 

这可能不是你正在寻找的东西(这不是一个“简单”的解决scheme,将你的标签发送到屏幕的底部),但是我仍然想要给你一个有趣的替代解决scheme:

ScrollableTabHost被devise成像TabHost一样,但是有一个额外的滚动视图以适应更多的项目。

也许挖掘到这个开源项目,你会发现你的问题的答案。 如果我看到什么更容易,我会回到你身边。

当我尝试将它们放在屏幕的底部时,我遇到了与安卓标签相同的问题。 我的scheme是不使用布局文件,并在代码中创build选项卡,我也想从每个选项卡触发活动,这似乎有点太复杂,使用其他方法,所以,这里是示例代码来克服这个问题:

添加的选项卡function于Android的和放置,它们

是的,看: 链接 ,但他使用XML布局,而不是活动,以创build新的选项卡,所以把他的XML代码(设置paddingTop为FrameLayout – 0px),然后写代码:

 public class SomeActivity extends ActivityGroup { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TabHost tab_host = (TabHost) findViewById(R.id.edit_item_tab_host); tab_host.setup(this.getLocalActivityManager()); TabSpec ts1 = tab_host.newTabSpec("TAB_DATE"); ts1.setIndicator("tab1"); ts1.setContent(new Intent(this, Registration.class)); tab_host.addTab(ts1); TabSpec ts2 = tab_host.newTabSpec("TAB_GEO"); ts2.setIndicator("tab2"); ts2.setContent(new Intent(this, Login.class)); tab_host.addTab(ts2); TabSpec ts3 = tab_host.newTabSpec("TAB_TEXT"); ts3.setIndicator("tab3"); ts3.setContent(new Intent(this, Registration.class)); tab_host.addTab(ts3); tab_host.setCurrentTab(0); } 

}

我推荐使用此代码进行稳定的工作,它为选项卡中的嵌套片段(例如嵌套的MapFragment)进行优化,并在“不保留活动”上进行testing: https ://stackoverflow.com/a/23150258/2765497