LOGO OA教程 ERP教程 模切知识交流 PMS教程 CRM教程 开发文档 其他文档  
 
网站管理员

【Android】--底部Tab的实现

admin
2013年2月25日 14:40 本文热度 4042

国际惯例先上图:


tabhost布局文件,注意tabhost,tabcontent和tabs这三个id一定要正确

[html]
  1. xml version="1.0" encoding="utf-8"?>  
  2. <TabHost xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:id="@android:id/tabhost"  
  4.     android:layout_width="match_parent"  
  5.     android:layout_height="match_parent" >  
  6.     <RelativeLayout android:orientation="vertical"    
  7.         android:layout_width="match_parent"   
  8.         android:layout_height="match_parent">  
  9.         <FrameLayout android:id="@android:id/tabcontent"    
  10.                 android:layout_width="match_parent"   
  11.                 android:layout_height="match_parent" />  
  12.             <TabWidget android:id="@android:id/tabs"  
  13.                 android:layout_width="match_parent"  
  14.                 android:layout_height="wrap_content"   
  15.                 android:background="@drawable/selector"  
  16.                 android:layout_alignParentBottom="true">  
  17.             TabWidget>  
  18.     RelativeLayout>  
  19. TabHost>  
每一个tab项的布局文件,上面图片下面是文字,

[html]
  1. xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     android:orientation="vertical" >  
  6.     <ImageView android:id="@+id/tab_iv_icon"  
  7.         android:layout_width="match_parent"   
  8.         android:layout_height="28.0dip"   
  9.         android:scaleType="fitCenter"/>  
  10.     <TextView android:id="@+id/tab_tv_text"  
  11.         android:layout_width="match_parent"   
  12.         android:layout_height="wrap_content"   
  13.         android:textSize="12.0sp"   
  14.         android:textColor="#FFFFFF"  
  15.         android:ellipsize="marquee"   
  16.         android:gravity="center"   
  17.         android:singleLine="true"   
  18.         android:marqueeRepeatLimit="1"/>  
  19. LinearLayout>  
最后是MainActivity继承自TabActivity

[java]
  1. public class MainActivity extends TabActivity {  
  2.     private TabHost tabHost;  
  3.     private static final String HOME = "主页";    
  4.     private static final String REFER = "提及";    
  5.     private static final String ABOUT = "关于";  
  6.     private static final String SEARCH = "搜索";    
  7.     private static final String MORE = "更多";   
  8.     //内容Intent   
  9.     private Intent homeIntent;  
  10.     private Intent referIntent;  
  11.     private Intent aboutIntent;  
  12.     private Intent searchIntent;  
  13.     private Intent moreIntent;  
  14.   
  15.     public void onCreate(Bundle savedInstanceState) {  
  16.         super.onCreate(savedInstanceState);  
  17.         setContentView(R.layout.tabhost);//设置TabHost使用的布局文件   
  18.           
  19.         tabHost=this.getTabHost();  
  20.         tabHost.setFocusable(true);  
  21.         prepareIntent();  
  22.         setupIntent();  
  23.           
  24.     }  
  25.       
  26.     private void setupIntent(){  
  27.         tabHost.addTab(buildTabSpec(HOME,R.drawable.icon_1_n, homeIntent));  
  28.         tabHost.addTab(buildTabSpec(REFER,R.drawable.icon_2_n, referIntent));  
  29.         tabHost.addTab(buildTabSpec(ABOUT,R.drawable.icon_3_n, aboutIntent));  
  30.         tabHost.addTab(buildTabSpec(SEARCH,R.drawable.icon_4_n, searchIntent));  
  31.         tabHost.addTab(buildTabSpec(MORE,R.drawable.icon_5_n, moreIntent));  
  32.     }  
  33.   
  34.     private TabSpec buildTabSpec(String tag, int icon, Intent intent) {  
  35.         View view = View.inflate(MainActivity.this, R.layout.tab, null);  
  36.         ((ImageView)view.findViewById(R.id.tab_iv_icon)).setImageResource(icon);  
  37.         ((TextView)view.findViewById(R.id.tab_tv_text)).setText(tag);  
  38.         return tabHost.newTabSpec(tag)  
  39.                 .setIndicator(view)  
  40.                 .setContent(intent);  
  41.     }  
  42.   
  43.     private void prepareIntent() {  
  44.         homeIntent=new Intent(this, HomeActivity.class);  
  45.         referIntent=new Intent(this, ReferActivity.class);  
  46.         aboutIntent=new Intent(this, AboutActivity.class);  
  47.         searchIntent=new Intent(this,SearchActivity.class);  
  48.         moreIntent=new Intent(this, MoreActivity.class);  
  49.     }  
  50.   
  51. }  

该文章在 2013/2/25 16:37:08 编辑过
关键字查询
相关文章
正在查询...
点晴ERP是一款针对中小制造业的专业生产管理软件系统,系统成熟度和易用性得到了国内大量中小企业的青睐。
点晴PMS码头管理系统主要针对港口码头集装箱与散货日常运作、调度、堆场、车队、财务费用、相关报表等业务管理,结合码头的业务特点,围绕调度、堆场作业而开发的。集技术的先进性、管理的有效性于一体,是物流码头及其他港口类企业的高效ERP管理信息系统。
点晴WMS仓储管理系统提供了货物产品管理,销售管理,采购管理,仓储管理,仓库管理,保质期管理,货位管理,库位管理,生产管理,WMS管理系统,标签打印,条形码,二维码管理,批号管理软件。
点晴免费OA是一款软件和通用服务都免费,不限功能、不限时间、不限用户的免费OA协同办公管理系统。
Copyright 2010-2024 ClickSun All Rights Reserved