当前位置: 代码迷 >> Iphone >> ActivityGroup兑现iPhone风格的底部tab菜单
  详细解决方案

ActivityGroup兑现iPhone风格的底部tab菜单

热度:85   发布时间:2016-04-25 06:35:31.0
ActivityGroup实现iPhone风格的底部tab菜单

?

java代码
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);	}}
?
xml布局
<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:orientation="vertical" 		          android:layout_width="fill_parent" 		          android:layout_height="fill_parent"		          android:id="@+id/bodyL" 		          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:orientation="vertical" 			          android:layout_width="wrap_content"			          android:layout_height="fill_parent" 			          android:id="@+id/home"		              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:orientation="vertical" 			          android:layout_width="wrap_content"			          android:layout_height="fill_parent" 			          android:id="@+id/gamebox"  			          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:orientation="vertical" 			          android:layout_width="wrap_content"			          android:id="@+id/team" 			          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:orientation="vertical" 			         android:layout_width="wrap_content"			         android:id="@+id/more" 			         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>
1 楼 forever-liang 2012-04-10  
无王道,无真相
  相关解决方案