LOGO OA教程 ERP教程 模切知識交流 PMS教程 CRM教程 開發(fā)文檔 其他文檔  
 
網(wǎng)站管理員

【Android】--底部Tab的實(shí)現(xiàn)

admin
2013年2月25日 14:40 本文熱度 4439

國際慣例先上圖:




tabhost布局文件,注意tabhost,tabcontent和tabs這三個(gè)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>  
每一個(gè)tab項(xiàng)的布局文件,上面圖片下面是文字,





[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 = "關(guān)于";  

  6.     private static final String SEARCH = "搜索";    

  7.     private static final String MORE = "更多";   

  8.     //內(nèi)容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);//設(shè)置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 編輯過
關(guān)鍵字查詢
相關(guān)文章
正在查詢...
點(diǎn)晴ERP是一款針對中小制造業(yè)的專業(yè)生產(chǎn)管理軟件系統(tǒng),系統(tǒng)成熟度和易用性得到了國內(nèi)大量中小企業(yè)的青睞。
點(diǎn)晴PMS碼頭管理系統(tǒng)主要針對港口碼頭集裝箱與散貨日常運(yùn)作、調(diào)度、堆場、車隊(duì)、財(cái)務(wù)費(fèi)用、相關(guān)報(bào)表等業(yè)務(wù)管理,結(jié)合碼頭的業(yè)務(wù)特點(diǎn),圍繞調(diào)度、堆場作業(yè)而開發(fā)的。集技術(shù)的先進(jìn)性、管理的有效性于一體,是物流碼頭及其他港口類企業(yè)的高效ERP管理信息系統(tǒng)。
點(diǎn)晴WMS倉儲管理系統(tǒng)提供了貨物產(chǎn)品管理,銷售管理,采購管理,倉儲管理,倉庫管理,保質(zhì)期管理,貨位管理,庫位管理,生產(chǎn)管理,WMS管理系統(tǒng),標(biāo)簽打印,條形碼,二維碼管理,批號管理軟件。
點(diǎn)晴免費(fèi)OA是一款軟件和通用服務(wù)都免費(fèi),不限功能、不限時(shí)間、不限用戶的免費(fèi)OA協(xié)同辦公管理系統(tǒng)。
Copyright 2010-2025 ClickSun All Rights Reserved

黄频国产免费高清视频,久久不卡精品中文字幕一区,激情五月天AV电影在线观看,欧美国产韩国日本一区二区
亚洲欧美中文字幕在线播放 | 在线人成视频播放午夜福 | 精品国产一区二区三区久久狼 | 日韩欧美精品一中文字幕 | 日本欧美真人三级在线A | 视频一区二区三区四区在线综合网 |