如何处理 Android 选项卡和子选项卡
我正在寻找创建一个使用选项卡的 Android 应用程序。
要求
当用户选择一个选项卡并返回到同一选项卡时,不应有加载期(最好)。
每个选项卡将包含一个列表视图。
在其中一个选项卡中,我必须使用子选项卡。
就是这样。
我非常喜欢的一个很好的例子(尽管我没有尝试该应用程序)是 http://www.usatoday。 com/android/。
I am looking to create an Android application that uses Tabs.
Requirements
When a user selects a tab and gets back to the same tab, there shouldn't be a loading period (preferably).
Each tab will contain a listview.
In one of the tabs, I will have to use subtabs.
And that's it.
One great example I really liked (although I didn't try the app) is http://www.usatoday.com/android/.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有两个想法您需要考虑:
1.) 子选项卡不能使用 Activity 来实现,因为
ActivityGroup
无法包装另一个ActivityGroup
2.) 选项卡中的选项卡大大增加了布局复杂性少量。尤其是关于< 2.0 设备您将很容易遇到
StackOverflowExceptions
。 android官方博客上也有一篇关于它的博文,当我找到它时我会更新答案。[编辑]
我们开始: http://android-developers.blogspot .com/2009/04/future-proofing-your-apps.html
相关部分是:
考虑到每个 Tabhost 都会增加大约 4 层深度,因此使用双 Tab 很快就会达到 10 层深度。
请记住,“使用活动”作为选项卡只是一个骗局,它们只是层次结构中的附加视图。
Two thinks you need to consider:
1.) Subtabs cannot be implemented using Activities, since an
ActivityGroup
cannot wrap anotherActivityGroup
2.) Tabs in Tabs blow up Layout complexity quite a bit. Especially on < 2.0 devices you'll easily run into
StackOverflowExceptions
. There was also a blog post about it on the official android blog, I'll update the answer when I find it.[EDIT]
There we go: http://android-developers.blogspot.com/2009/04/future-proofing-your-apps.html
The relevant part is:
Considering that every tabhost adds about 4 layers of depth, you'll reach a depth of 10 with double tabs pretty soon.
Keep in mind that "using activities" as tabs is just a sham, they are just additional views within your hierarchy.
我刚刚开发了一个选项卡式应用程序,并使用以下函数在代码中创建选项卡。该函数使用意图,这意味着每当选择一个选项卡时,就会使用意图将活动加载到选项卡主体中。该函数在主活动中调用。
NewsList Activity 中的列表视图是由 XML 制作的,如下所示:
响应下面 Fabios 的评论:
是的,请使用可见性属性或尝试使用下面提到的方式实现选项卡:
其中布局文件如下:
I just developed a tabbed application and I used the following function to create tabs in code. The function uses intents which mean when ever a tab is selected an Activity is loaded in the tab body using intent. This function is called in main activity.
The list view in NewsList Activity is made by XML as following:
In Response to Fabios' comment below:
Yes wither use visibility property or try implementing tabs using the way mentioned below:
Where as Layout file is as below: