我已经看到一些关于此的喋喋不休,但没有确定。 有没有办法将TabWidget中的标签放到屏幕的底部? 如果是这样,怎么样?Android:底部的标签
我试过以下,但没有奏效:
一)设置以下的FrameLayout
B中的tabwidget)设置tabwidget的重力 “底”
谢谢! llappall
我已经看到一些关于此的喋喋不休,但没有确定。 有没有办法将TabWidget中的标签放到屏幕的底部? 如果是这样,怎么样?Android:底部的标签
我试过以下,但没有奏效:
一)设置以下的FrameLayout
B中的tabwidget)设置tabwidget的重力 “底”
谢谢! llappall
这可能不是您正在寻找的东西(将标签发送到屏幕底部并不是一个“简单”的解决方案),但仍然是我想标记给您的一个有趣的替代解决方案:
ScrollableTabHost旨在表现得像TabHost,但有一个附加的滚动视图,以适应更多的项目......
可能挖掘到这个开源项目,你会发现一个回答你的问题。如果我看到更简单的东西,我会回到你身边。
是,请参阅:link,但他使用了XML的布局,不活动,以创造新的标签,所以把他的XML代码(集paddingTop为FrameLayout里 - 0像素),然后写代码:
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
双方的FrameLayout和TabWidgetandroid:layout_weight="1"
android:layout_weight="0"
(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>
分隔线实际上是硬编码的。我试图改变用于标签的可绘制并找到它。总是无赖。 – 2010-04-26 15:58:21
你确实发现它在Widget中的编码位置,并且没有界面可以改变它?令人惊讶和令人失望。所以目前唯一的解决方案是在其上方手动绘制分隔线,并将标签下方的线保留下来...... – stormin986 2010-04-26 22:10:08
我的方法是将标签简单重新对齐到底部。对于具有此功能和其他功能的自定义TabWidget,看起来像这个人制作了一个支持标签垂直对齐的标签,还有一些其他自定义选项,例如标签背景/图标。 – stormin986 2010-04-26 22:20:26
试试吧;) 只是看的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但您是否注意到屏幕上方的黑色/灰色条?你是如何删除它的? – 2010-11-03 14:32:22
我正在使用它将选项卡小部件发布到窗体的左侧。 – 2012-05-16 03:19:42
我试图将它们放在屏幕底部时遇到了与安卓标签相同的问题。我的方案是不使用布局文件并在代码中创建选项卡,我还希望从每个选项卡触发活动,使用其他方法似乎有点太复杂,因此,下面是用于解决问题的示例代码:
不在这里发布代码会使您的答案不完整。 – BryanH 2011-07-05 01:04:33
对于所有那些尝试删除tabWidget分隔线的人来说,这里是一个示例项目(及其相应的教程),这对于定制选项卡非常适用,因此可以在选项卡处于底部时删除问题。 Eclipse项目:android-custom-tabs; 原文解释:blog; 希望这有助于。
不知道是否会为Android的所有版本(特别是那些定制UI的东西)工作,但我可以通过添加
android:layout_marginBottom="-3dp"
到TabWidget XML,除去底部的灰色栏。 ..
非常容易和重点!谢谢! – MaKo 2012-05-28 04:42:19
有一种方法可以删除该行。
1)按照本教程: android-tabs-with-fragments
2)然后应用RelativeLayout的更改,Leaudro上面所建议的(应用的布局道具所有FrameLayouts)。
您还可以将ImageView添加到项目#1中的tab.xml中,并获得非常类似于标签的iPhone。
下面是我正在工作的一个截图。我还有一些工作要做,主要是为图标选择一个选择器,并确保水平分布均匀,但你明白了。 就我而言,我使用的是片段,但是相同的主体应该适用于标准的标签视图。
自从您发布这条消息以来,它已经有一段时间了,但您的链接现在说__欢迎使用nginx!__,页面上没有任何其他内容。 – DroidDev 2014-09-09 12:47:04
这不是我的网站,sop我不能控制它。 经过这段时间,系统已经发生了很大的变化,你可能不应该为你的Android用户实现这种接口,他们会希望事情现在有点不同。 – 2014-09-09 16:00:23
我建议使用稳定的工作这段代码,它在标签嵌套片段优化(例如嵌套MapFragment)和测试“不保留活动”:https://stackoverflow.com/a/23150258/2765497
<?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>
请定义“没有工作”。 – CommonsWare 2010-03-07 13:54:43
[看这里](http://stackoverflow.com/a/6992662/593709)如果你想iPhone像标签主机。 – 2012-03-21 11:09:25
我从下面的网站使用一个。 它的工作[http://kpbird.blogspot.com/2011/05/androidbottom-tabbar-control.html](http://kpbird.blogspot.com/2011/05/androidbottom-tabbar-control.html) – Juliousraj 2011-09-07 05:27:57