Code Section:
<? 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 = "wr Ap_content "android: textColor =" @ android: color/white "android: textSize =" 18sp "/> </LinearLayout> <! -- Dynamically load view in the middle --> <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"> <! -- Function module 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"/> <! -- Function module 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"/> <! -- Function module button 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>
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);}/*** set content * @ param str */public void setContentText (String str) {content. setText (str);}/*** Set background color * @ 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 ("Module 1 ");}}
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 ("module 2 ");}}
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 ("module 3 ");}}