android ActivityGroup

实现点击底部不同图片按钮切换不同的Activity,并在中间显示Activity对应的ContentView。

1.实现代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schema.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout android:gravity="center_horizontal"
      android:background="@android:color/background_dark"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content">
    <TextView
        android:id="@+id/cust_title"
        android:textColor="@android:color/white"
        android:textSize="28sp"
        android:text="模块1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
</LinearLayout>
<ScrollView android:id="@+id/containerBody"
             android:layout_weight="1"
             android:layout_height="fill_parent"
             android:layout_width="fill_parent"/>
<LinearLayout android:background="@android:color/black"
      android:layout_gravity="bottom"
      android:orientation="horizontal"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content">
     <ImageView android:id="@+id/btnModule1"
          android:src="@android:drawable/ic_dialog_dialer"
          android:layout_marginLeft="7dip"
          android:layout_marginTop="3dip"
          android:layout_marginBottom="3dip"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"/>
     <ImageView android:id="@+id/btnModule2"
          android:src="@android:drawable/ic_dialog_info"
          android:layout_marginLeft="7dip"
          android:layout_marginTop="3dip"
          android:layout_marginBottom="3dip"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"/>
      <ImageView android:id="@+id/btnModule3"
          android:src="@android:drawable/ic_dialog_alert"
          android:layout_marginLeft="7dip"
          android:layout_marginTop="3dip"
          android:layout_marginBottom="3dip"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>

2.
class MainActivity extends ActivityGroup{
private ScrollView container; 
public void onCreate(Bundle savedInstanceState){
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_main);
   container=(ScrollView)findViewById(R.id.containerBody);
   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(MainActivity.this,ModuleView1.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView());
     }
   });
   btnModule2.setOnClickListener(new OnClickListener(){
     public void onClick(View v){
       container.removeAllViews();
       container.addView(getLocalActivityManager().startActivity("Module2",new Intent(MainActivity.this,ModuleView2.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView());
     }
   });
   btnModule3.setOnClickListener(new OnClickListener(){
     public void onClick(View v){
       container.removeAllViews();
       container.addView(getLocalActivityManager().startActivity("Module3",new Intent(MainActivity.this,ModuleView3.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView());
     }
   });
}
}

代码说明:
a)ModuleView1,ModuleView2,ModuleView3分别继承自Activity.
b)想动态改变标题可以通过cust_title获取TextView进行设置.




你可能感兴趣的:(ActivityGroup)