要求点击底部不同图片按钮切换不同的Activity,并在中间显示Activity对应的ContentView。
二、 实现代码
2.1 layout.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:orientation="vertical" android:layout_height="fill_parent"> <LinearLayout android:gravity="center_horizontal" android:background="@drawable/myinfor2" 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"></TextView> </LinearLayout> <!-- 中间动态加载View --> <ScrollView android:measureAllChildren="true" android:id="@+id/containerBody" android:layout_weight="1" android:layout_height="fill_parent" android:layout_width="fill_parent"> </ScrollView> <LinearLayout android:background="@android:color/black" android:layout_gravity="bottom" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content"> <!-- 功能模块按钮1 --> <ImageView android:id="@+id/btnModule1" android:src="@android:drawable/ic_dialog_dialer" android:layout_marginLeft="7dp" android:layout_marginTop="3dp" android:layout_marginBottom="3dp" 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="7dp" android:layout_marginTop="3dp" android:layout_marginBottom="3dp" 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="7dp" android:layout_marginTop="3dp" android:layout_marginBottom="3dp" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> </LinearLayout> |
2.2 TestView.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
代码说明:
- ModuleView1、ModuleView2、 ModuleView3分别继承自Activity。
- 想动态改变标题可以通过cust_title获取TextView进行设置。