我看到一些关于这个的传言,但没有确切的。 有没有办法把 TabWidget 中的选项卡放到屏幕底部? 如果是这样,怎么做?
我试过以下方法,但没有效果:
A)将 tabwidget 设置在框架布局之下 B)设置桌面小部件的重力为“底部”
谢谢! Llappall
这可能并不是你想要的(将标签页发送到屏幕底部并不是一个“简单”的解决方案) ,但是我还是想给你提供一个有趣的替代方案:
ScrollableTabHost 的设计行为与 TabHost 相似,但是通过额外的 scrollview 可以容纳更多的项..。
也许深入研究这个开源项目,你会找到问题的答案。如果我看到什么更容易的,我会回来找你。
是的,参见: 链接,但是他使用 xml 布局,而不是活动来创建新的选项卡,所以把他的 xml 代码(设置 paddingTop for 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); }
}
这里有一个最简单、最健壮和可伸缩的解决方案,可以让选项卡出现在屏幕底部。
layout_height
wrap_content
android:layout_weight="1"
android:layout_weight="0"
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>
当我试图把它们放在屏幕底部时,我也遇到了同样的问题。我的场景是不使用布局文件并在代码中创建选项卡,我还希望从每个选项卡中激发活动,使用其他方法似乎有点过于复杂,因此,下面是克服这个问题的示例代码:
在 android 中添加制表符并放置它们
对于那些试图删除 tabWidget 的分隔线的人来说,这里有一个示例项目(及其相应的教程) ,它非常适合定制选项卡,从而在选项卡位于底部时消除问题。 Eclipse 项目: 机器人-自定义标签; 原文解释: 博客; 希望这个有帮助。
不确定它是否适用于所有版本的 Android (特别是那些有自定义用户界面的版本) ,但是我可以通过添加来移除底部的灰色条
android:layout_marginBottom="-3dp"
到 TabWidget XML..。
在选项卡活动的底部显示选项卡有两种方式。
请检查 有关详情,请浏览。
有一种方法可以移除这条线。
1)遵循这个教程: 带有片段的 android 制表符
2)然后应用莱奥德罗上面建议的 RelativeLayout 更改(将布局道具应用于所有 FrameLayouts)。
您还可以将 ImageView 添加到项目 # 1中的 tab.xml 中,从而获得与 iPhone 非常相似的选项卡外观。
这是我正在做的东西的截图。我还有一些工作要做,主要是为图标做一个选择器,并确保平等的水平分布,但你得到的想法。 在我的例子中,我使用的是片段,但是同样的原则应该适用于标准选项卡视图。
我建议使用这段代码来进行稳定的工作,它针对制表符中的嵌套片段(例如嵌套的图片片段)进行了优化,并测试了“不保留活动”: https://stackoverflow.com/a/23150258/2765497