Android entry 15th ActivityGroup implement Tab

Source: Internet
Author: User

Many client software and browser software like to use Tab pages to manage content. In addition to the TabHost control, you can also use ImageButton + ActivityGroup to implement Tab pages. You can use ImageButton + ActivityGroup to implement Tab tabs. You can add a Sub Activity Window as a View to the container specified by ActivityGroup, this article uses LinearLayout as the container to load Sub Activity.

Next, paste the example running:

 

The following is the status change of the Sub Activity lifecycle during switchover:

 

When switching from subActivity1 to subActivity2, the resources of subActivity1 will be completely released.

The source code of main. xml of the main Activity is as follows:

View plaincopy to clipboardprint?
<? Xml version = "1.0" encoding = "UTF-8"?>
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: orientation = "vertical" android: layout_width = "fill_parent"
Android: layout_height = "fill_parent">
<LinearLayout android: id = "@ + id/LinearLayout01"
Android: layout_height = "wrap_content" android: layout_width = "fill_parent">
<ImageButton android: layout_width = "wrap_content"
Android: layout_height = "wrap_content" android: id = "@ + id/ibtnTab1"
Android: background = "@ drawable/png1298"> </ImageButton>
<ImageButton android: layout_width = "wrap_content"
Android: layout_height = "wrap_content" android: id = "@ + id/ibtnTab2"
Android: background = "@ drawable/png1292"> </ImageButton>
</LinearLayout>
<LinearLayout android: id = "@ + id/LinearLayout02"
Android: layout_width = "fill_parent" android: layout_height = "fill_parent"> </LinearLayout>
</LinearLayout>
<? Xml version = "1.0" encoding = "UTF-8"?>
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: orientation = "vertical" android: layout_width = "fill_parent"
Android: layout_height = "fill_parent">
<LinearLayout android: id = "@ + id/LinearLayout01"
Android: layout_height = "wrap_content" android: layout_width = "fill_parent">
<ImageButton android: layout_width = "wrap_content"
Android: layout_height = "wrap_content" android: id = "@ + id/ibtnTab1"
Android: background = "@ drawable/png1298"> </ImageButton>
<ImageButton android: layout_width = "wrap_content"
Android: layout_height = "wrap_content" android: id = "@ + id/ibtnTab2"
Android: background = "@ drawable/png1292"> </ImageButton>
</LinearLayout>
<LinearLayout android: id = "@ + id/LinearLayout02"
Android: layout_width = "fill_parent" android: layout_height = "fill_parent"> </LinearLayout>
</LinearLayout>
 

The XML source code of Sub Activity (listview. xml) is as follows:

View plaincopy to clipboardprint?
<? Xml version = "1.0" encoding = "UTF-8"?>
<LinearLayout android: id = "@ + id/LinearLayout01"
Xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "fill_parent" android: layout_height = "fill_parent">
<ListView android: id = "@ + id/MyListView" android: layout_width = "fill_parent"
Android: layout_height = "fill_parent">
</ListView>
</LinearLayout>
<? Xml version = "1.0" encoding = "UTF-8"?>
<LinearLayout android: id = "@ + id/LinearLayout01"
Xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "fill_parent" android: layout_height = "fill_parent">
<ListView android: id = "@ + id/MyListView" android: layout_width = "fill_parent"
Android: layout_height = "fill_parent">
</ListView>
</LinearLayout>

The source code of testActivityGroup. java is as follows:

View plaincopy to clipboardprint?
Package com. testActivityGroup;

Import android. app. ActivityGroup;
Import android. content. Intent;
Import android. OS. Bundle;
Import android. view. View;
Import android. view. Window;
Import android. widget. ImageButton;
Import android. widget. LinearLayout;
Import android. widget. ListView;

Public class testActivityGroup extends ActivityGroup {
/** Called when the activity is first created .*/
LinearLayout container; // container for loading sub Activity
ImageButton ibtnTab1, ibtnTab2;
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );

Container = (LinearLayout) findViewById (R. id. LinearLayout02 );
IbtnTab1 = (ImageButton) this. findViewById (R. id. ibtnTab1 );
IbtnTab1.setOnClickListener (new ClickEvent ());
IbtnTab2 = (ImageButton) this. findViewById (R. id. ibtnTab2 );
IbtnTab2.setOnClickListener (new ClickEvent ());
}

Class ClickEvent imple

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.