展会信息港展会大全

ActivityGroup实现iPhone风格的底部tab菜单
来源:互联网   发布日期:2015-10-13 07:33:41   浏览:3080次  

导读:public class ActsGroup extends ActivityGroup { private LinearLayout bodyView; private LinearLayout home, gamebox, team, more; private int flag = 0; // 通过标记跳转不同的页面,......

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);

}

}

<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>

赞助本站

人工智能实验室

相关热词: iPhone风格 tab 菜单

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港