目的跟圖片一樣按下下面的圖示會切換不同的Activity

ActivityGroup  

======================================================

主Activity.xml

 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="@drawable/activity_group_background"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- 中間動態加載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="#ffffff"
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="@drawable/activity_calculate"
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="@drawable/activity_about"
android:layout_marginLeft="7dp" android:layout_marginTop="3dp"
android:layout_marginBottom="3dp" android:layout_width="wrap_content"
android:layout_height="wrap_content" />

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

 

<Button
android:id="@+id/btnModule3"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="訓練" />

 

</LinearLayout>
</LinearLayout>


===============================================================================================


public class TestView extends ActivityGroup {

    
private ScrollView container = null;

    @Override
    
protected void onCreate(Bundle savedInstanceState) {
        
super.onCreate(savedInstanceState);
        
// 隱藏標題列
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        
// 設置View
        setContentView(R.layout.layout);

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

        
// 按下Image1切換到Activity1
        ImageView btnModule1 = (ImageView) findViewById(R.id.btnModule1);
        btnModule1.setOnClickListener(
new OnClickListener() {
            @Override
            
public void onClick(View v) {
                container.removeAllViews();
                container.addView(getLocalActivityManager().startActivity(
                        
"Module1",
                        
new Intent(TestView.this, ModuleView1.class)
                                .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
                        .getDecorView());
            }
//上面的ModuleView1.class 是Activity1 也有自己的xml 下面以此類推
        });

        // 按下Image2切換到Activity2
        ImageView btnModule2 = (ImageView) findViewById(R.id.btnModule2);
        btnModule2.setOnClickListener(
new OnClickListener() {
            @Override
            
public void onClick(View v) {
                container.removeAllViews();
                container.addView(getLocalActivityManager().startActivity(
                        
"Module2",
                        
new Intent(TestView.this, ModuleView2.class)
                                .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
                        .getDecorView());
            }
        });

        // 按下Image3切換到Activity3
        ImageView btnModule3 = (ImageView) findViewById(R.id.btnModule3);
        btnModule3.setOnClickListener(
new OnClickListener() {
            @Override
            
public void onClick(View v) {
                container.removeAllViews();
                container.addView(getLocalActivityManager().startActivity(
                        
"Module3",
                        
new Intent(TestView.this, ModuleView3.class)
                                .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
                        .getDecorView());
            }
        });
    }
}


參考:http://www.cnblogs.com/over140/archive/2010/09/07/1820876.html


arrow
arrow
    文章標籤
    ActivityGroup Android Activity
    全站熱搜

    cookiesp 發表在 痞客邦 留言(0) 人氣()