Android 将TabHost放在最下方显示

本文详细解析了如何使用TabHost和TabActivity进行布局设计与代码整合,包括使用视图ID设置菜单和使用Intent设置显示界面的实现方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

布局文件:

<?xml version="1.0" encoding="utf-8"?>
<TabHost android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent"
  xmlns:android="http://schemas.android.com/apk/res/android">
    <LinearLayout android:orientation="vertical" android:id="@id/ll_main_tab" android:layout_width="fill_parent" android:layout_height="fill_parent">
        <FrameLayout android:gravity="center" android:id="@android:id/tabcontent" android:fadingEdge="none" android:fadingEdgeLength="0.0dip" android:layout_width="fill_parent" android:layout_height="0.0dip" android:layout_weight="1.0">
        <RelativeLayout android:id="@+id/tabFirst" 

             android:layout_width="fill_parent" 

             android:layout_height="fill_parent" 

             android:orientation="vertical">  

         <AnalogClock 

             android:id="@+id/widget31" 

             android:layout_width="wrap_content" 

             android:layout_height="wrap_content" 

             android:layout_centerInParent="true">  

         </AnalogClock>  

         </RelativeLayout>

         <RelativeLayout android:id="@+id/tabSecond" 

             android:layout_width="fill_parent" 

             android:layout_height="fill_parent" 

             android:orientation="vertical">  

             <DigitalClock 
                 android:layout_centerInParent="true" 

                 android:layout_width="wrap_content" 

                 android:layout_height="wrap_content">  

             </DigitalClock>  

         </RelativeLayout>  
            
        
        </FrameLayout>
        <TabWidget android:id="@android:id/tabs" android:background="@drawable/tab_btn_bg_normal" android:layout_width="fill_parent" android:layout_height="wrap_content" />
    </LinearLayout>
</TabHost>


代码区:

package com.tanghy.tab.activity;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;

public class MainActivity extends TabActivity {
	
	TabHost tabHost;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        tabHost = getTabHost();
        
        tabHost.addTab(tabHost.newTabSpec("one").setIndicator("aaaa").setContent(R.id.tabFirst));
        tabHost.addTab(tabHost.newTabSpec("two").setIndicator("bbb").setContent(R.id.tabSecond));
        tabHost.addTab(tabHost.newTabSpec("three").setIndicator("ccc").setContent(new Intent().setClass(this, LogActivity.class)));
        
        tabHost.setCurrentTab(0);
        
    }


}


通过代码我们看出,我们可以使用view的id来设置一个菜单也可以使用intent来设置一个显示界面。。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值