您的位置:首页 > 其它

Tabhost每个tab中放入多个Activity

2013-04-19 15:41 274 查看




效果点击Start以后跳转到下个view

原网址:http://k-beta.com/tabhost-tab-more-activity.html

外面是个tabhost(用于底部tab栏)每个tab中有一个Activity,这个很普遍。

但有时需要每个tab中有多个页面,也就是说需要 在一个tab中跳转不同的Activity。如果直接用intent跳转,那么会出现新的Activity不会显示原来设定的Tabhost,这不是我们的目的。最终网络上找到了解决办法,原网址原文是http://united-coders.com网站的http://united-coders.com/nico-heid/use-android-activitygroup-within-tabhost-to-show-different-activity

Use Android ActivityGroup within TabHost to show different Activity

(在Tabhost中使用Android的ActivityGroup展示不同的Activity)

When you’re using a TabHost each tab has it’s own Activity. Now image you want to change the Activity for a certain tab. If you just go on and create
a new Activity and display it, your Tab Layout is no longer visible.

(当你使用Tabhost时,每个Tab都可以设置一个Activity,现在,假设你需要在当前的tab中跳转Activity,如果你只是单单的新建一个Activity,并且显示在屏幕上的话,你的TabHost将会不可见。)

For that reason you need a ActivityGroup within the Tab where you want to change the Activity.

(为此,你需要在你想使用多个Activity的tab中使用ActivityGroup)

An ActivityGroup is: A screen that contains and runs multiple embedded activities.

(ActivityGroup就是一个包含并且可以运行多个Activity的显示控件)

Let’s look at this at a real life example. An Android app that shows your podcasts. In the first Activity you get to see all podcasts by subscription.
If you touch the subscription, you see the single podcasts you’ve downloaded for that subscription.

(让我们看看这个实际的例子,一个Android 程序 显示你的博客,在第一个Activity中你会看到所有的博客的描述,如果你点击描述,那么你会看到一个单独的详细的博客内容。。。。。(好吧,其实这句我没怎么翻译好。。。。))

The Tabhost contains three tabs, one for the MediaPlayer, one for the archive and one for available downloads.

(这个Tabhost包含三个tab,其中一个是MediaPlayer,一个是文章页,另一个是下载页面。)

The ArchiveGroup takes care which Activity is shown in the second tab. With setContentView you can bring the View to the front.

(ArchiveGroup 主要负责将哪个Activity展示在第二个Tab中,使用setContentView可以将该view显示在最前面。)具体实例可以查看demo中的内容。

You need to tell the ActivityGroup which view is to be on top and set the appropriate Flag, so that the View will be on top.

(你需要告诉ActivityGroup ,哪一个view应该是最表面展现的,并且设置合适的Flag标志,设置了这些之后,这个view才会显示在最表面。)

小demo下载~~~~~~http://download.csdn.net/detail/yusewuhen/5276855
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: