代码部分:
<?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:gravity="center_horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" > <TextView android:id="@+id/cust_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@android:color/white" android:textSize="18sp" /> </LinearLayout> <!-- 中间动态加载view --> <ScrollView android:id="@+id/containerBody" android:layout_width="fill_parent" android:layout_height="300dip" > </ScrollView> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" android:orientation="horizontal" > <!-- 功能模块1 --> <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" /> <!-- 功能模块2 --> <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" /> <!-- 功能模块按钮3 --> <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>
package com.yek; import android.app.ActivityGroup; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.ImageView; import android.widget.ScrollView; import android.widget.TextView; public class LearnActivity extends ActivityGroup implements OnClickListener{ private TextView title; private ScrollView contain; private ImageView btnOne; private ImageView btnTwo; private ImageView btnThree; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_group_layout); initView(); setListener(); } private void initView(){ title = (TextView)findViewById(R.id.cust_title); contain = (ScrollView)findViewById(R.id.containerBody); btnOne = (ImageView)findViewById(R.id.btnModule1); btnTwo = (ImageView)findViewById(R.id.btnModule2); btnThree = (ImageView)findViewById(R.id.btnModule3); } private void setListener(){ btnOne.setOnClickListener(this); btnTwo.setOnClickListener(this); btnThree.setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.btnModule1: btnOneListener(ModuleView1.class); break; case R.id.btnModule2: btnOneListener(ModuleView2.class); break; case R.id.btnModule3: btnOneListener(ModuleView3.class); break; } } private void btnOneListener(Class clazz){ contain.removeAllViews(); View view = getLocalActivityManager().startActivity("Module1", new Intent(this,clazz).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView(); contain.addView(view); } }
<?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" > <TextView android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="@string/hello" android:id="@+id/content" /> </LinearLayout>
package com.yek; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class ModuleBaseActivity extends Activity { private TextView content; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); content = (TextView)findViewById(R.id.content); } /** * 设置内容 * @param str */ public void setContentText(String str){ content.setText(str); } /** * 设置背景色 * @param colorId */ public void setBackground(int colorId){ content.setBackgroundColor(colorId); } }
package com.yek; import android.graphics.Color; import android.os.Bundle; public class ModuleView1 extends ModuleBaseActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setBackground(Color.RED); setContentText("模块一"); } }
package com.yek; import android.graphics.Color; import android.os.Bundle; public class ModuleView2 extends ModuleBaseActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setBackground(Color.GREEN); setContentText("模块二"); } }
package com.yek; import android.graphics.Color; import android.os.Bundle; public class ModuleView3 extends ModuleBaseActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setBackground(Color.BLUE); setContentText("模块三"); } }