(reprint) Android two tab paging way: Tabactivity and Activitygroup and Android project several common application architectures

Source: Internet
Author: User

There are two common methods of tab paging in Android:

I. The combination of tabactivity and tabhost

1. Main class inheritance Tabactivity

public class Tagpage extends tabactivity

2. Get the current Tabhost object

Final Tabhost tabhost = Gettabhost ();

3. Add tab page tab, here is the key to link each page into activity. The jump of the page is the activity's jump.

Tabhost.addtab (Tabhost.newtabspec ("Tab1"). Setindicator ("TaB2", Getresources (). getdrawable (R.DRAWABLE.A1)). SetContent (New Intent (this, page1.class));

Ii. Activitygroup and GridView the combination

1. Main class inheritance Activitygroup

public class Gridviewtabpage extends Activitygroup

2. Get activity view for each sub-page

Intent Intent = new Intent (gridviewtabpage.this, Page1.class);

Subpageview = Getlocalactivitymanager (). StartActivity ("Subpageview" + I, intent);

3. Loading into the container

Pagecontainer.addview (Subpageview Getdecorview (), layoutparams.fill_parent, layoutparams.fill_parent);

If you have too many tab options, you can use the gallery+activitygroup combination of implementations.

1. Single activity Architecture (recommended)

The homepage is activity, the inside page is view, the bottom column of the head is common, just changes the text and the pattern. The bottom navigation bar is RadioButton, the middle can slide to toggle. Jump quickly, but the home page is not smooth.

The benefits of this architecture are clear thinking and low system operating overhead. The downside is poor control, code clutter, and poor lifecycle management.

2. Multiple activity-use baseactivity to provide commonality

3, multiple activity-use tabactivity

Mainactivity (tabactivity), sub-activity (baseactivty)

The code and ideas are clear, baseactivity have the same back and head bottom bar.

3.1 Mainactivity (tabactivity), son activity (Activitygroup), grandson activity (baseactivty)

PS: For jumps that need to implement multiple activity within a tabhost

3.2 RadioButton with tabactivity jump (code very clear)

4, multiple Activity-activitygroup (official has been marked as not recommended)

The bottom bar is implemented with the GridView, with RadioButton at the bottom.

(reprint) Android two tab paging way: Tabactivity and Activitygroup and Android project several common application architectures

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.