• ActivityGroup+LinearLayout实现iphone风格的底部tab菜单


    public class ActsGroup extends ActivityGroup {
     
        private LinearLayout bodyView;
        private LinearLayout home, gamebox, team, more;
        private int flag = 0; // 通过标记跳转不同的页面,显示不同的菜单项
        // private String parameter = Constant.BUTTON_HOME;// 初始化加载
     
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            requestWindowFeature(Window.FEATURE_NO_TITLE); // 无标题
            super.onCreate(savedInstanceState);
            setContentView(R.layout.acts_group);
            initMainView();
            // 主界面开始接收参数
            Bundle bundle = getIntent().getExtras();
            if (null != bundle) {
                flag = bundle.getInt("flag");
            }
            // 默认显示
            showView(flag);
     
            home.setOnClickListener(new OnClickListener() {
     
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    flag = 0;
                    showView(flag);
     
                }
            });
            gamebox.setOnClickListener(new OnClickListener() {
     
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    flag = 1;
                    showView(flag);
     
                }
            });
            team.setOnClickListener(new OnClickListener() {
     
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    flag = 2;
                    showView(flag);
     
                }
            });
            more.setOnClickListener(new OnClickListener() {
     
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    flag = 3;
                    showView(flag);
     
                }
            });
     
        }
     
        /*
         * 初始化主界面底部的功能菜单
         */
        public void initMainView() {
            bodyView = (LinearLayout) findViewById(R.id.bodyL);
            home = (LinearLayout) findViewById(R.id.home);
            gamebox = (LinearLayout) findViewById(R.id.gamebox);
            team = (LinearLayout) findViewById(R.id.team);
            more = (LinearLayout) findViewById(R.id.more);
        }
     
        // 在主界面中显示其他界面
        public void showView(int flag) {
            switch (flag) {
            case 0:
                showHome();
                break;
            case 1:
                showGamebox();
                break;
            case 2:
                showTeam();
                break;
            case 3:
                showMore();
                break;
            default:
                break;
            }
        }
     
        public void showHome() {
            bodyView.removeAllViews();
            bodyView.addView(getLocalActivityManager().startActivity("home",
                    new Intent(ActsGroup.this, MainActivity.class)).getDecorView());
            home.setBackgroundResource(R.drawable.tab_highlight);
            gamebox.setBackgroundResource(R.drawable.tab_background);
            more.setBackgroundResource(R.drawable.tab_background);
            team.setBackgroundResource(R.drawable.tab_background);
        }
     
        public void showGamebox() {
            bodyView.removeAllViews();
            bodyView.addView(getLocalActivityManager().startActivity("gamebox",
                    new Intent(ActsGroup.this, Menu2Activity.class)).getDecorView());
            gamebox.setBackgroundResource(R.drawable.tab_highlight);
            home.setBackgroundResource(R.drawable.tab_background);
            more.setBackgroundResource(R.drawable.tab_background);
            team.setBackgroundResource(R.drawable.tab_background);
        }
     
        public void showTeam() {
            bodyView.removeAllViews();
            bodyView.addView(getLocalActivityManager().startActivity("team",
                    new Intent(ActsGroup.this, Menu2Activity.class)).getDecorView());
            team.setBackgroundResource(R.drawable.tab_highlight);
            home.setBackgroundResource(R.drawable.tab_background);
            more.setBackgroundResource(R.drawable.tab_background);
            gamebox.setBackgroundResource(R.drawable.tab_background);
        }
     
        public void showMore() {
            bodyView.removeAllViews();
            bodyView.addView(getLocalActivityManager().startActivity("more",
                    new Intent(ActsGroup.this, Menu2Activity.class)).getDecorView());
            more.setBackgroundResource(R.drawable.tab_highlight);
            home.setBackgroundResource(R.drawable.tab_background);
            team.setBackgroundResource(R.drawable.tab_background);
            gamebox.setBackgroundResource(R.drawable.tab_background);
        }
     
    }
    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
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <!--动态显示界面 -->
        <LinearLayout
            android:id="@+id/bodyL"
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="0.95">
        </LinearLayout>
        <!--底部功能菜单栏 -->
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/bottomlist"
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0.05">
            <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/home"
                android:orientation="vertical"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:layout_weight="5"
                android:gravity="center_horizontal">
                <ImageView
                    android:background="@drawable/home"
                    android:layout_gravity="top|center"
                    android:layout_height="35dp"
                    android:layout_width="32dp"
                    android:layout_marginTop="4dp"
                    />
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="20dp"
                    android:text="@string/home"
                    />
            </LinearLayout>
            <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/gamebox"
                android:orientation="vertical"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:layout_weight="5"
                android:gravity="center_horizontal">
                <ImageView
                    android:background="@drawable/gamebox"
                    android:layout_gravity="top|center"
                    android:layout_height="35dp"
                    android:layout_width="32dp"
                    android:layout_marginTop="4dp"
                    />
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="20dp"
                    android:text="@string/gamebox"
                    />
            </LinearLayout>
            <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/team"
                android:orientation="vertical"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:layout_weight="5"
                android:gravity="center_horizontal">
                <ImageView
                    android:background="@drawable/team"
                    android:layout_gravity="top|center"
                    android:layout_height="35dp"
                    android:layout_width="32dp"
                    android:layout_marginTop="4dp"
                    />
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="20dp"
                    android:text="@string/team"
                    />
            </LinearLayout>
            <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/more"
                android:orientation="vertical"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:layout_weight="5"
                android:gravity="center_horizontal">
                <ImageView
                    android:background="@drawable/more"
                    android:layout_gravity="top|center"
                    android:layout_height="35dp"
                    android:layout_width="32dp"
                    android:layout_marginTop="4dp"
                    />
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="20dp"
                    android:text="@string/more"
                    />
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>
  • 相关阅读:
    Tomcat7,Tomcat8 的manager 配置
    JavaScript 获得当前日期+时间
    CentOS 安装jdk 1.8
    nginx文件结构与解析,例子
    jxl解析多个excel工作表-java代码
    一个上传图片,预览图片的小demo
    利用DES,C#加密,Java解密代码
    CentOS安装Nginx
    摄像机标定--很懒的方法
    slam-g2o安装失败的解决问题
  • 原文地址:https://www.cnblogs.com/Free-Thinker/p/3479075.html
Copyright © 2020-2023  润新知