--------------------------------------------素材----------------------------------------------------
|
|
|
--------------------------------------------AndroidManifest.xml----------------------------------
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ch15"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- 我的账户页 -->
<activity android:name=".AccountActivity"></activity>
<!-- 分类页 -->
<activity android:name=".CategoryActivity"></activity>
<!-- Home页 -->
<activity android:name=".HomeActivity"></activity>
<!-- 更多页 -->
<activity android:name=".MoreActivity"></activity>
<!-- 购物车页 -->
<activity android:name=".ShopCartActivity"></activity>
</application>
</manifest>
--------------------------------------------activity_main.xml-------------------------------------
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- tbar -->
<include layout="@layout/tbar" />
<!-- body -->
<LinearLayout
android:id="@+id/body"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/body_back" android:layout_weight="1">
</LinearLayout>
<!-- bbar -->
<include layout="@layout/bbar"/>
</LinearLayout>
--------------------------------------------tbar.xml-----------------------------------------------
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/title" android:background="@drawable/bar_top"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/hello_world"/>
</LinearLayout>
--------------------------------------------bbar.xml-----------------------------------------------
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/bar_bottom" android:layout_weight="0.01">
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" android:id="@+id/group">
<RadioButton
android:id="@+id/btnA"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:button="@drawable/bar_home_normal" />
<RadioButton
android:id="@+id/btnB"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:button="@drawable/bar_treasure_normal" />
<RadioButton
android:id="@+id/btnC"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:button="@drawable/bar_shoppingcart_normal" />
<RadioButton
android:id="@+id/btnD"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:button="@drawable/bar_account_normal" />
<RadioButton
android:id="@+id/btnE"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:button="@drawable/bar_more_normal" />
</RadioGroup>
</LinearLayout>
--------------------------------------------activity_home.xml------------------------------------
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="home"/>
</RelativeLayout>
--------------------------------------------activity_category.xml---------------------------------
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="category"/>
</RelativeLayout>
--------------------------------------------activity_account.xml---------------------------------
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="account"/>
</RelativeLayout>
--------------------------------------------activity_shopcart.xml--------------------------------
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="shopcart"/>
</RelativeLayout>
--------------------------------------------activity_more.xml-----------------------------------
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="more" />
</RelativeLayout>
--------------------------------------------MainActivity.java-----------------------------------
package com.ch15;
import android.app.ActivityGroup;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;
/**
*
* 项目名称:com.ch15
* 类名称:MainActivity
* 类描述:启动页面
* 创建人:方勇
* 创建时间:2012-11-23 下午10:26:03
* Copyright (c) 方勇-版权所有
*/
public class MainActivity extends ActivityGroup {
/* 底部菜单,bbar */
private RadioGroup group;
/* 中间部分,body */
private LinearLayout body;
/* 顶部菜单,tbar */
private TextView view_title;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViews();
setListeners();
}
private void findViews() {
group = (RadioGroup) findViewById(R.id.group);
body = (LinearLayout) findViewById(R.id.body);
view_title = (TextView) findViewById(R.id.title);
}
private void setListeners() {
group.setOnCheckedChangeListener(onCheckedChangeListener);
}
private OnCheckedChangeListener onCheckedChangeListener = new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
body.removeAllViews();
switch (checkedId) {
/* Home页 */
case R.id.btnA:
/* 设置跳转 */
Intent homeIntent = new Intent();
homeIntent.setClass(MainActivity.this, HomeActivity.class);
/*
* 1、 Activity和Task(栈)的关系
* 栈(Task)就像一个容器,而Activity就相当与填充这个容器的东西,
* 第一个东西(Activity)则会处于最下面,最后添加的东西(Activity)则会在最低端。从Task中取出东西(Activity)则是从最顶端取出,也
* 就是说最先取出的是最后添加的东西(Activity),一次类推,最后取出的是第一次添加的Activity,
* 而Activity在Task中的顺序是 可以控制的,那则在Activity跳转时用到Intent Flag
*
* 2、Intent.FLAG
* 如果activity在task存在,拿到最顶端,不会启动新的Activity
* intent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
*
* 如果activity在task存在,将Activity之上的所有Activity结束掉
* intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
*
* 默认的跳转类型,将Activity放到一个新的Task中
* intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
*
* 如果Activity已经运行到了Task,再次跳转不会再运行这个Activity
* intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
*/
homeIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
/* 获取跳转页面Activity绑定的Layout视图 */
View homeView = getLocalActivityManager().startActivity("home", homeIntent).getDecorView();
/* 添加Layout到Body布局中 */
body.addView(homeView);
/* 设置标题文本 */
view_title.setText("home");
break;
/* 分类页 */
case R.id.btnB:
/* 设置跳转 */
Intent categoryIntent = new Intent();
categoryIntent.setClass(MainActivity.this, CategoryActivity.class);
categoryIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
View categoryView = getLocalActivityManager().startActivity("category", categoryIntent).getDecorView();
body.addView(categoryView);
view_title.setText("category");
break;
/* 购物车页 */
case R.id.btnC:
/* 设置跳转 */
Intent shopcartIntent = new Intent();
shopcartIntent.setClass(MainActivity.this, ShopCartActivity.class);
shopcartIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
View shopcartView = getLocalActivityManager().startActivity("shopcart", shopcartIntent).getDecorView();
body.addView(shopcartView);
view_title.setText("shopcart");
break;
/* 我的账户页 */
case R.id.btnD:
/* 设置跳转 */
Intent accountIntent = new Intent();
accountIntent.setClass(MainActivity.this, AccountActivity.class);
accountIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
View accountView = getLocalActivityManager().startActivity("account", accountIntent).getDecorView();
body.addView(accountView);
view_title.setText("account");
break;
/* 更多页 */
case R.id.btnE:
/* 设置跳转 */
Intent moreIntent = new Intent();
moreIntent.setClass(MainActivity.this, MoreActivity.class);
moreIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
View moreView = getLocalActivityManager().startActivity("more", moreIntent).getDecorView();
body.addView(moreView);
view_title.setText("more");
break;
}
}
};
}
--------------------------------------------HomeActivity.java-----------------------------------
package com.ch15;
import android.app.Activity;
import android.os.Bundle;
/**
*
* 项目名称:com.ch15
* 类名称:HomeActivity
* 类描述: 首页
* 创建人:方勇
* 创建时间:2012-11-23 下午10:25:51
* Copyright (c) 方勇-版权所有
*/
public class HomeActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
}
}
--------------------------------------------CategoryActivity.java-------------------------------
package com.ch15;
import android.app.Activity;
import android.os.Bundle;
/**
*
* 项目名称:com.ch15
* 类名称:CategoryActivity
* 类描述: 分类页
* 创建人:方勇
* 创建时间:2012-11-23 下午10:25:34
* Copyright (c) 方勇-版权所有
*/
public class CategoryActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_category);
}
}
--------------------------------------------AccountActivity.java--------------------------------
package com.ch15;
import android.app.Activity;
import android.os.Bundle;
/**
*
* 项目名称:com.ch15
* 类名称:AccountActivity
* 类描述: 我的账户页
* 创建人:方勇
* 创建时间:2012-11-23 下午10:25:18
* Copyright (c) 方勇-版权所有
*/
public class AccountActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_account);
}
}
--------------------------------------------ShopCartActivity.java-------------------------------
package com.ch15;
import android.app.Activity;
import android.os.Bundle;
public class ShopCartActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_shopcart);
}
}
--------------------------------------------MoreActivity.java-----------------------------------
package com.ch15;
import android.app.Activity;
import android.os.Bundle;
public class MoreActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_more);
}
}
--------------------------------------------效果图------------------------------------------------
<!--EndFragment-->