如何在Android 4.0中创建选项卡式布局?
既然 TabActivity 已被弃用,那么使用片段构建选项卡式界面的正确方法是什么?我见过的每个教程都采用不同的方法。其中一些极其复杂,将平凡的编程主题推向了火箭科学领域。什么给?
我正在为 ICS Android 4.0 编码。
谢谢。
Now that TabActivity is deprecated, what is the proper way to build a tabbed interface using fragments? Every tutorial I have seen takes a different approach. Some of them are supremely complicated pushing a mundane programming topic to the rocket science territory. What gives?
I am coding for ICS Android 4.0.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
现在首选的方法是使用 ActionBar 为您提供的选项卡。鉴于您喜欢这个选项,设置起来非常容易。借助 ActionbarSherlock,您甚至可以将应用程序一直移植回 1.6。
然而,它并不适合所有情况。例如,您可能需要将这些选项卡置于片段内、同时显示多个片段的屏幕上。在这种情况下,您必须坚持使用“已弃用”的方法来设置选项卡,使用 TabWidget。这很丑陋,但有可能。
编辑:
检查杰夫的评论。正如他指出的,我错了,TabWidget 仍然完全有效,TabAvtivity 是这里已弃用的类!
The preferred way now is to use the tabs that ActionBar gives you. It's quite easy to set up, given that you like this option. With ActionbarSherlock, you can even port your app all the way back to 1.6.
It's not suitable for every case however. For example, you might need those tabs to be inside a fragment, on a screen that displays multiple fragments at once. In that case, you have to stick with the "deprecated" methods to set up the tabs, using a TabWidget. It's ugly, but possible.
Edit:
Check Jeff's comment. As he pointed out, I was wrong, TabWidget is still perfectly valid, TabAvtivity is the deprecated class here!