Android:底部的选项卡
我看到一些关于这个的讨论,但没有明确的。 有没有办法将 TabWidget 中的选项卡放在屏幕底部? 如果是这样,怎么办?
我尝试了以下方法,但没有成功:
a) 将 tabwidget 设置在框架布局下方
b) 将 tabwidget 的重力设置为“底部”
谢谢! 拉帕尔
I've seen some chatter about this, but nothing definite.
Is there a way to put the tabs in a TabWidget to the bottom of the screen?
If so, how?
I've tried the following, but didn't work:
a) setting the tabwidget below the framelayout
b) setting the tabwidget's gravity to "bottom"
Thanks!
llappall
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
这是在屏幕底部获取选项卡的最简单、最强大且可扩展的解决方案。
layout_height
设置为wrap_content
android:layout_weight="1"
android:layout_weight="0"
(0 是默认值,但为了强调、可读性等)android:layout_marginBottom="-4dp"
(删除底部分隔线)完整代码:
Here's the simplest, most robust, and scalable solution to get tabs on the bottom of the screen.
layout_height
towrap_content
on both FrameLayout and TabWidgetandroid:layout_weight="1"
android:layout_weight="0"
(0 is default, but for emphasis, readability, etc)android:layout_marginBottom="-4dp"
(to remove the bottom divider)Full code:
尝试一下;)
只需观看 FrameLayout(@id/tabcontent) 的内容,因为我不知道在滚动的情况下它将如何处理...在我的情况下它有效,因为我使用 ListView 作为选项卡的内容。 :)
希望有帮助。
Try it ;)
Just watch the content of the FrameLayout(@id/tabcontent), because I don't know how it will handle in case of scrolling... In my case it works because I used ListView as the content of my tabs. :)
Hope it helps.
有一种方法可以去掉线。
1)按照本教程操作:
android-tabs-with-fragments
2) 然后应用更改 Leaudro 上面建议的relativeLayout(将布局属性应用于所有 FrameLayout)。
您还可以将 ImageView 添加到项目 #1 中的 tab.xml 中,并获得非常像 iPhone 的选项卡外观。
这是我现在正在做的事情的屏幕截图。我还有一些工作要做,主要是为图标制作一个选择器并确保平等的水平分布,但你明白了。
就我而言,我使用的是片段,但相同的原则应该适用于标准选项卡视图。
There is a way to remove the line.
1) Follow this tutorial:
android-tabs-with-fragments
2) Then apply the RelativeLayout change that Leaudro suggested above (apply the layout props to all FrameLayouts).
You can also add an ImageView to the tab.xml in item #1 and get a very iPhone like look to the tabs.
Here is a screenshot of what I'm working on right now. I still have some work to do, mainly make a selector for the icons and ensure equal horizontal distribution, but you get the idea.
In my case, I'm using fragments, but the same principals should apply to a standard tab view.
不确定它是否适用于所有版本的 Android(尤其是那些具有自定义 UI 内容的版本),但我能够通过添加到
TabWidget XML 来删除底部的灰色条...
Not sure if it will work for all versions of Android (especially those with custom UI stuff), but I was able to remove the gray bar at the bottom by adding
to the TabWidget XML...
对于所有尝试删除 tabWidget 分隔线的人,这里有一个示例项目(及其各自的教程),它非常适合自定义选项卡,从而消除选项卡位于底部时的问题。
Eclipse 项目: android-custom-tabs ;
原文解释:博客;
希望这有帮助。
For all those of you that try to remove the separating line of the tabWidget, here is an example project (and its respective tutorial), that work great for customizing the tabs and thus removing problems when tabs are at bottom.
Eclipse Project: android-custom-tabs ;
Original explanation: blog;
Hope this helped.
有两种方法可以在选项卡活动的底部显示选项卡。
请检查 链接更多详细信息。
There are two ways to display tabs at the bottom of a tab activity.
Please check the link for more details.
这可能不完全是您正在寻找的(这不是将选项卡发送到屏幕底部的“简单”解决方案),但仍然是一个有趣的替代解决方案,我想向您标记:
ScrollableTabHost 的设计与 TabHost 类似,但具有额外的滚动视图以适应更多项目...
也许深入研究这个开源项目你会找到你的问题的答案。如果我看到任何更容易的事情,我会回来找你。
This may not be exactly what you're looking for (it's not an "easy" solution to send your Tabs to the bottom of the screen) but is nevertheless an interesting alternative solution I would like to flag to you :
ScrollableTabHost is designed to behave like TabHost, but with an additional scrollview to fit more items ...
maybe digging into this open-source project you'll find an answer to your question. If I see anything easier I'll come back to you.
当我尝试将 Android 选项卡放置在屏幕底部时,我也遇到了同样的问题。我的场景是不使用布局文件并在代码中创建选项卡,我还希望从每个选项卡触发活动,这使用其他方法似乎有点太复杂,因此,这里是解决该问题的示例代码:
添加-tabs-in-android-and-placing-他们
I was having the same problem with android tabs when trying to place them on the bottom of the screen. My scenario was to not use a layout file and create the tabs in code, I was also looking to fire activities from each tab which seemed a bit too complex using other approaches so, here is the sample code to overcome the problem:
adding-tabs-in-android-and-placing-them
是的,请参阅:链接,但他使用了 xml 布局,而不是活动来创建新选项卡,所以放入他的xml代码(为FrameLayout设置paddingTop - 0px)然后编写代码:
}
Yes, see: link, but he used xml layouts, not activities to create new tab, so put his xml code (set paddingTop for FrameLayout - 0px) and then write the code:
}
我建议使用此代码来实现稳定的工作,它针对选项卡中的嵌套片段(例如嵌套 MapFragment)进行了优化,并在“不保留活动”上进行了测试: https://stackoverflow.com/a/23150258/2765497
I recomend use this code for stable work, it optimized for nested fragments in tab (for example nested MapFragment) and tested on "do not keep activities": https://stackoverflow.com/a/23150258/2765497