91网首页-91网页版-91网在线观看-91网站免费观看-91网站永久视频-91网站在线播放

LOGO OA教程 ERP教程 模切知識交流 PMS教程 CRM教程 開發文檔 其他文檔  
 
網站管理員

【Android】--底部Tab的實現

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

國際慣例先上圖:




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-2025 ClickSun All Rights Reserved

主站蜘蛛池模板: 日韩高清在线亚洲 | 午夜伦理电影网 | 区四区在线 | 97人人超| 女同欧洲 | 国产男女爽爽爽免 | 中文字幕无线精品 | 国产精品人 | 91女同| 国内偷拍视频网页 | 国产最新电影在线观 | 日韩精品成 | 中文字幕丰满伦孑 | 精品va在线观看 | 91国产爽黄神话 | 国产宅男z资源网站 | 爱豆传媒电影 | 中文字幕精品一区 | 成人欧美日韩一区 | 精品国语任你躁 | 国产在线观看专线一 | 国产偷精品免费观看 | 拍拍拍无挡国产精品 | 果冻传媒视频电影 | 午夜福利院在线观看 | 国产公妇仑在线观看 | 国产女同女互慰 | 国内成人一区 | 91精品亚洲 | 午夜亚洲一区二区福 | 国产精选在 | 中文字幕在 | 国产精品综合一区 | 欧美影院一区 | 国产不卡视频cr | 日韩国产精品一区二 | 国产午夜福利精品 | 区二区三区三 | 日韩午夜福利电影 | 国产亚洲一欧美 | 国产午夜福利免 |