开发者

Android: What kind of layout is used to have different views controlled by buttons on the same activity?

Consider the Android native clock app开发者_C百科. Here is a picture of it, the graphics looks modified (compared to mine at least) but it gets the point across:

Android: What kind of layout is used to have different views controlled by buttons on the same activity?

See those tabs on top? When you click them, a new view pops up below in the main body of the activity. Currently it is alarm clock, but if you clicked timer or stopwatch that would change. How is this accomplished? From what I can tell it is the same activity (clicking only causes a different button to be highlighted, there is no transition to a new activity).

I'm sure this is a totally simple question, but I haven't come across it yet and I tried to search for it but I guess I wasn't explaining it well enough for the google and SO search engine... Thanks!


Tabs can be setup to pop different views :

LocalActivityManager localActivityManager = new LocalActivityManager(this, false);
tabHost.setup(localActivityManager);

TabSpec spec = tabHost.newTabSpec("tab1").setIndicator("My Tab1").setContent(R.id.layout_tab1);
tabHost.addTab(spec);

spec = tabHost.newTabSpec("tab2").setIndicator("My Tab2").setContent(R.id.layout_tab2);
tabHost.addTab(spec);


spec = tabHost.newTabSpec("tab3").setIndicator("My Tab3").setContent(R.id.layout_tab3);
tabHost.addTab(spec);

Or they can be setup to pop different activities :

someActivity = new Intent().setClass(this, SomeActivity.class);
spec = tabHost.newTabSpec("tab3").setIndicator("My Activity Tab").setContent(someActivity);
tabHost.addTab(spec);

(notice how the setContent allows you to specify an int (pointing to a layout ID), or an intent (pointing to an activity)

Unsure how the calendar app is implemented, but like with many things in Android, choices are plentiful.


Check out Android Tab Layout

http://developer.android.com/resources/tutorials/views/hello-tabwidget.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜