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