TabHost 添加底部菜单

本文介绍了一种使用 Android 的 TabActivity 实现底部导航栏的方法。通过 TabHost 和 RadioGroup 构建了包含四个标签页(首页、分类、商城和个人中心)的应用界面,并详细展示了如何设置各个标签页的内容和切换监听。
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/page_bg" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="0.0dip"
            android:layout_weight="1.0" />

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0.0"
            android:visibility="gone" />

        <RadioGroup
            android:id="@+id/main_radio"
            android:layout_width="fill_parent"
            android:layout_height="65dp"
            android:layout_gravity="bottom"
            android:background="@drawable/main_tab_bg"
            android:gravity="center_vertical"
            android:orientation="horizontal" >

            <RadioButton
                android:id="@+id/radio_button0"
                style="@style/main_tab_bottom"
                android:layout_marginBottom="3dp"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:layout_marginTop="3dp"
                android:checked="true"
                android:drawableTop="@drawable/main_jiong_icon"
                android:tag="radio_button0"
                android:text="首页" />

            <RadioButton
                android:id="@+id/radio_button1"
                style="@style/main_tab_bottom"
                android:layout_marginBottom="3dp"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:layout_marginTop="3dp"
                android:drawableTop="@drawable/main_shen_icon"
                android:tag="radio_button1"
                android:text="分类" />

            <RadioButton
                android:id="@+id/radio_button2"
                style="@style/main_tab_bottom"
                android:layout_marginBottom="3dp"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:layout_marginTop="3dp"
                android:drawableTop="@drawable/main_high_icon"
                android:tag="radio_button2"
                android:text="商城" />

            <RadioButton
                android:id="@+id/radio_button3"
                style="@style/main_tab_bottom"
                android:layout_marginBottom="3dp"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:layout_marginTop="3dp"
                android:drawableTop="@drawable/main_more_icon"
                android:tag="radio_button3"
                android:text="个人中心" />
        </RadioGroup>
    </LinearLayout>

</TabHost>


 
public class TabPageActivity extends TabActivity {
	public TabHost mth;
	public static final String TAB_ONE= "首页";
	public static final String TAB_TWO = "分类";
	public static final String TAB_THREE = "商城";
	public static final String TAB_FOUR  = "个人中心";
	public RadioGroup radioGroup;
	public static boolean unlock = false;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main); 
		
		this.initTableHost();

	}


	private void initTableHost() {
		mth = this.getTabHost();

		TabSpec ts1 = mth.newTabSpec(TAB_ONE).setIndicator(TAB_ONE);
		ts1.setContent(new Intent(TabPageActivity.this, HomePageActivity.class));
		mth.addTab(ts1);

		TabSpec ts2 = mth.newTabSpec(TAB_TWO).setIndicator(TAB_TWO);
		ts2.setContent(new Intent(TabPageActivity.this, FenLeiActivity.class));
		mth.addTab(ts2);
		
		TabSpec ts3 = mth.newTabSpec(TAB_THREE).setIndicator(TAB_THREE);
		Intent intent = new Intent(TabPageActivity.this,
				ShangchengWebViewActivity.class);
		intent.putExtra( Constants.WEB_VIEW_URL, "http://www.baidu.com");
		intent.putExtra(Constants.MENU_NAME, "商城");
		ts3.setContent(intent);
		mth.addTab(ts3);

		

		TabSpec ts4 = mth.newTabSpec(TAB_FOUR).setIndicator(TAB_FOUR);
		ts4.setContent(new Intent(TabPageActivity.this, MoreActivity.class));
		mth.addTab(ts4);

		this.radioGroup = (RadioGroup) findViewById(R.id.main_radio);
		mth.setCurrentTabByTag(TAB_ONE);
		radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				switch (checkedId) {
				case R.id.radio_button0:
					mth.setCurrentTabByTag(TAB_ONE);
					break;
				case R.id.radio_button1:
					mth.setCurrentTabByTag(TAB_TWO);
					break;
				case R.id.radio_button2:
					mth.setCurrentTabByTag(TAB_THREE);
					break;
				case R.id.radio_button3:
					mth.setCurrentTabByTag(TAB_FOUR);
					break;

				}
			}
		});
		
	}

}



MATLAB主动噪声和振动控制算法——对较大的次级路径变化具有鲁棒性内容概要:本文主要介绍了一种在MATLAB环境下实现的主动噪声和振动控制算法,该算法针对较大的次级路径变化具有较强的鲁棒性。文中详细阐述了算法的设计原理与实现方法,重点解决了传统控制系统中因次级路径动态变化导致性能下降的问题。通过引入自适应机制和鲁棒控制策略,提升了系统在复杂环境下的稳定性和控制精度,适用于需要高精度噪声与振动抑制的实际工程场景。此外,文档还列举了多个MATLAB仿真实例及相关科研技术服务内容,涵盖信号处理、智能优化、机器学习等多个交叉领域。; 适合人群:具备一定MATLAB编程基础和控制系统理论知识的科研人员及工程技术人员,尤其适合从事噪声与振动控制、信号处理、自动化等相关领域的研究生和工程师。; 使用场景及目标:①应用于汽车、航空航天、精密仪器等对噪声和振动敏感的工业领域;②用于提升现有主动控制系统对参数变化的适应能力;③为相关科研项目提供算法验证与仿真平台支持; 阅读建议:建议读者结合提供的MATLAB代码进行仿真实验,深入理解算法在不同次级路径条件下的响应特性,并可通过调整控制参数进一步探究其鲁棒性边界。同时可参考文档中列出的相关技术案例拓展应用场景。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值