ActivityGroup代替TabHost

package cn.fn;

import android.app.ActivityGroup;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.ScrollView;

public class GroupActivity extends ActivityGroup {

    private ScrollView container = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // 隐藏标题栏
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        // 设置视图
        setContentView(R.layout.main);

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

        // 模块1
        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(GroupActivity.this, Test1.class)
                                .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
                        .getDecorView());
            }
        });

        // 模块2
        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(GroupActivity.this, Test1.class)
                                .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
                        .getDecorView());
            }
        });

        // 模块3
        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(GroupActivity.this, Test1.class)
                                .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
                        .getDecorView());
            }
        });
    }
}




package cn.fn;

import android.app.Activity;
import android.os.Bundle;

public class Test1 extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout);
    }
}



<?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/icon" 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">
        <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" />
        <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" />
        <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>






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值