ActivityGroup使用实例

通过名字,就应该知道ActivityGroup是一个Activity的管理器,对于一组Activity的管理非常方面。下面是实例代码:

ActivityGroupTest.java

package app.imo;

import android.app.ActivityGroup;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.ImageView;
import android.widget.ScrollView;

/**
 * 
 * @author fengxiaowei
 * 
 */
public class ActivityGroupTest extends ActivityGroup {
	private ScrollView container = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// 隐藏标题栏
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		// 设置视图
		setContentView(R.layout.activity_group);

		container = (ScrollView) findViewById(R.id.containerBody);

		// 模块1
		ImageView btnModule1 = (ImageView) findViewById(R.id.btnModule1);
		btnModule1.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				container.removeAllViews();
				container.addView(getLocalActivityManager().startActivity("Module1",
						new Intent(ActivityGroupTest.this, ModuleView1.class).addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)).getDecorView());
			}
		});

		// 模块2
		ImageView btnModule2 = (ImageView) findViewById(R.id.btnModule2);
		btnModule2.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				container.removeAllViews();
				container.addView(getLocalActivityManager().startActivity("Module2",
						new Intent(ActivityGroupTest.this, ModuleView2.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView());
			}
		});

		// 模块3
		ImageView btnModule3 = (ImageView) findViewById(R.id.btnModule3);
		btnModule3.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				container.removeAllViews();
				container.addView(getLocalActivityManager().startActivity("Module3",
						new Intent(ActivityGroupTest.this, ModuleView3.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView());
			}
		});
	}

}

activity_group.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal" >

        <TextView
            android:id="@+id/cust_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="模块1"
            android:textColor="@android:color/white"
            android:textSize="28sp" >
        </TextView>
    </LinearLayout>
    <!-- 中间动态加载View -->

    <ScrollView
        android:id="@+id/containerBody"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:measureAllChildren="true" >
    </ScrollView>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:background="@android:color/black"
        android:orientation="horizontal" >

        <!-- 功能模块按钮1 -->

        <ImageView
            android:id="@+id/btnModule1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="3dp"
            android:layout_marginLeft="7dp"
            android:layout_marginTop="3dp"
            android:src="@android:drawable/ic_dialog_dialer" />
        <!-- 功能模块按钮2 -->


        <ImageView
            android:id="@+id/btnModule2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="3dp"
            android:layout_marginLeft="7dp"
            android:layout_marginTop="3dp"
            android:src="@android:drawable/ic_dialog_info" />
        <!-- 功能模块按钮3 -->

        <ImageView
            android:id="@+id/btnModule3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="3dp"
            android:layout_marginLeft="7dp"
            android:layout_marginTop="3dp"
            android:src="@android:drawable/ic_dialog_alert" />
    </LinearLayout>

</LinearLayout>

ModuleView1,ModuleView2,ModuleView3就是三个简单的Activity,这里就不贴代码了。

值得关注的地方:
Intent.FLAG_ACTIVITY_REORDER_TO_FRONT

你可能感兴趣的:(android,Module,layout,Class,dialog,encoding)