Android 默認Tab標簽大小及間距修改

一般來說,我都是用Android默認的Tab,但此時Android會根據你增加的Tab頁面平均分配Tab標簽,假如你只有兩個Tab,那么長度將會很長,并且其高度略微過高,并不好看,網上解決這個問題有些是自定義Tab。我們仍然使用默認的Tab解決此問題。

?

修改前 代碼、圖片如下:

?

[java]?view plaincopy
  1. import?android.app.TabActivity;??
  2. import?android.graphics.Color;??
  3. import?android.os.Bundle;??
  4. import?android.view.LayoutInflater;??
  5. import?android.widget.TabHost;??
  6. import?android.widget.TabHost.OnTabChangeListener;??
  7. ??
  8. public?class?MyTab?extends?TabActivity?implements?OnTabChangeListener?{??
  9. ??
  10. ????private?TabHost?myTabhost;??
  11. ??????
  12. ??????
  13. ????@Override??
  14. ????protected?void?onCreate(Bundle?savedInstanceState)?{??
  15. ????????//?TODO?Auto-generated?method?stub??
  16. ????????super.onCreate(savedInstanceState);??
  17. ????????myTabhost?=?this.getTabHost();??
  18. ????????//?get?Tabhost??
  19. ????????LayoutInflater.from(this).inflate(R.layout.main,??
  20. ????????????????myTabhost.getTabContentView(),?true);??
  21. ????????myTabhost.setBackgroundColor(Color.argb(150,?22,?70,?150));??
  22. ??
  23. ????????myTabhost.addTab(myTabhost.newTabSpec("One")//?make?a?new?Tab??
  24. ????????????????.setIndicator("查詢信息",?getResources().getDrawable(R.drawable.gimp))??
  25. ????????????????//?set?the?Title?and?Icon??
  26. ????????????????.setContent(R.id.widget_layout_Blue));??
  27. ????????//?set?the?layout??
  28. ??
  29. ????????myTabhost.addTab(myTabhost??
  30. ????????????????.newTabSpec("Two")??
  31. ????????????????//?make?a?new?Tab??
  32. ????????????????.setIndicator("簽到",??
  33. ????????????????????????getResources().getDrawable(R.drawable.mumule))??
  34. ????????????????//?set?the?Title?and?Icon??
  35. ????????????????.setContent(R.id.widget_layout_green));??
  36. ??
  37. ????}??
  38. ??
  39. ??????
  40. ??
  41. ????@Override??
  42. ????public?void?onTabChanged(String?tagString)?{??
  43. ????????//?TODO?Auto-generated?method?stub??
  44. ??????????
  45. ??????????
  46. ????}??
  47. ??
  48. }??



?

?

?

下面我就如何 改變Tab標簽大小及間距作出說明:

我在網上查閱文檔,如果要改變此大小或者間距,必須將標簽欄寬高設為 wrapContent(其他的我尚未驗證):以下為修改代碼及其效果:

?

?

[java]?view plaincopy
  1. import?android.app.TabActivity;??
  2. import?android.graphics.Color;??
  3. import?android.os.Bundle;??
  4. import?android.view.LayoutInflater;??
  5. import?android.view.View;??
  6. import?android.view.ViewGroup.LayoutParams;??
  7. import?android.widget.LinearLayout;??
  8. import?android.widget.TabHost;??
  9. import?android.widget.TabWidget;??
  10. import?android.widget.TabHost.OnTabChangeListener;??
  11. ??
  12. public?class?MyTab?extends?TabActivity?implements?OnTabChangeListener?{??
  13. ??
  14. ????private?TabHost?myTabhost;??
  15. ??????
  16. ??????
  17. ????@Override??
  18. ????protected?void?onCreate(Bundle?savedInstanceState)?{??
  19. ????????//?TODO?Auto-generated?method?stub??
  20. ????????super.onCreate(savedInstanceState);??
  21. ????????myTabhost?=?this.getTabHost();??
  22. ????????//?get?Tabhost??
  23. ????????LayoutInflater.from(this).inflate(R.layout.main,??
  24. ????????????????myTabhost.getTabContentView(),?true);??
  25. ????????myTabhost.setBackgroundColor(Color.argb(150,?22,?70,?150));??
  26. ??
  27. ????????myTabhost.addTab(myTabhost.newTabSpec("One")//?make?a?new?Tab??
  28. ????????????????.setIndicator("查詢信息",?getResources().getDrawable(R.drawable.gimp))??
  29. ????????????????//?set?the?Title?and?Icon??
  30. ????????????????.setContent(R.id.widget_layout_Blue));??
  31. ????????//?set?the?layout??
  32. ??
  33. ????????myTabhost.addTab(myTabhost??
  34. ????????????????.newTabSpec("Two")??
  35. ????????????????//?make?a?new?Tab??
  36. ????????????????.setIndicator("簽到",??
  37. ????????????????????????getResources().getDrawable(R.drawable.mumule))??
  38. ????????????????//?set?the?Title?and?Icon??
  39. ????????????????.setContent(R.id.widget_layout_green));??
  40. ??
  41. ????????//?首先得到標簽欄??
  42. ????????TabWidget?tabWidget?=?myTabhost.getTabWidget();??
  43. ????????//設置標簽欄寬高為?WRAP_CONTENT??
  44. ????????LinearLayout.LayoutParams?params?=?new?LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,?LayoutParams.WRAP_CONTENT);??
  45. ????????tabWidget.setLayoutParams(params);??
  46. ????????int?count?=?tabWidget.getChildCount();??
  47. ????????//得到每一個標簽,并設置其寬高??
  48. ?????????for?(int?i?=?0;?i?<?count;?i++)?{??
  49. ???????????????View?view?=?tabWidget.getChildTabViewAt(i);?????
  50. ???????????????view.getLayoutParams().height?=?50;?//tabWidget.getChildAt(i)??
  51. ???????????????view.getLayoutParams().width?=?80;??
  52. ??????????????}??
  53. ??
  54. ????}??
  55. ??
  56. ??????
  57. ??
  58. ????@Override??
  59. ????public?void?onTabChanged(String?tagString)?{??
  60. ????????//?TODO?Auto-generated?method?stub??
  61. ??????????
  62. ??????????
  63. ????}??
  64. ??
  65. }??



?

轉載于:https://www.cnblogs.com/firecode/archive/2012/11/26/2788684.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/274468.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/274468.shtml
英文地址,請注明出處:http://en.pswp.cn/news/274468.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

ui設計看的書_5本關于UI設計的書

ui設計看的書Want to develop a better eye and vocabulary for judging layouts, type choices and imagery?是否想開發一種更好的眼神和詞匯來判斷布局&#xff0c;類型選擇和圖像&#xff1f; According to performance experts, the best way to learn is to gain lots o…

GitHub 這8大超實用小技巧,99.9%的人都不知道!

大家好&#xff0c;我是若川。我持續組織了近一年的源碼共讀活動&#xff0c;感興趣的可以 點此掃碼加我微信 ruochuan12 參與&#xff0c;每周大家一起學習200行左右的源碼&#xff0c;共同進步。同時極力推薦訂閱我寫的《學習源碼整體架構系列》 包含20余篇源碼文章。歷史面試…

android的消息處理機制(圖+源碼分析)——Looper,Handler,Message

http://www.cnblogs.com/codingmyworld/archive/2011/09/12/2174255.html 還有相關的如下鏈接需要仔細check&#xff1a; http://mindtherobot.com/blog/159/android-guts-intro-to-loopers-and-handlers/ http://www.cnblogs.com/keyindex/articles/1822463.html轉載于:https:…

案例研究設計與方法-羅伯_旭進口重新設計-用戶體驗案例研究

案例研究設計與方法-羅伯Asahi Imports is a Japanese grocery store located in central Austin, Texas. It has a passionate following, over fifty years’ history, and strong business growth. But its website is showing its age, and not hitting its full potential…

Taro v3.6 代號為「Reach」,已發布 canary 版本

大家好&#xff0c;我是若川。我持續組織了近一年的源碼共讀活動&#xff0c;感興趣的可以 點此掃碼加我微信 lxchuan12 參與&#xff0c;每周大家一起學習200行左右的源碼&#xff0c;共同進步。同時極力推薦訂閱我寫的《學習源碼整體架構系列》 包含20余篇源碼文章。歷史面試…

axure rp 創建彈框_如何在Axure RP 9中創建交換機

axure rp 創建彈框Axure is a well-known prototyping tool with a lot of history, it has been around for years. You can create almost any kind of prototypes from simple ones to more complex ones with variables and logic without writing a single line of code (…

linux下使用cmake構建C/C++項目

cmake下載安裝&#xff1a; 下載地址: http://www.cmake.org/cmake/resources/software.html wget http://www.cmake.org/files/v2.8/cmake-2.8.10.2.tar.gz tar zxvf cmake-2.8.10.2.tar.gz cd cmake-2.8.10.2 ./configure gmake (不知道是不是必須的&#xff0c;提示要這么干…

用 Vue3 手撕了個企業級項目,真香!

最近幾年&#xff0c;隨著短視頻、小程序、直播帶貨的火爆&#xff0c;前端開發工程師越來越熱門&#xff0c;薪資待遇也快接近后端開發工程師了&#xff0c;前端領域進化為內卷重災區。然而伴隨著 Vue 3.0 的發布&#xff0c;前端技術也迎來了一次大革新&#xff0c;像是字節跳…

界面設計語言_使用任何語言設計界面的提示

界面設計語言Designing for international audiences is challenging. I spent most of my career in Australia designing exclusively in English. Australian English is ‘unique’ in the sense that we are really into slang, puns, idioms.為國際觀眾設計是具有挑戰性的…

托管代碼和非托管代碼

托管代碼和非托管代碼有什么區別呢&#xff1f;從字面上理解&#xff0c;只是一個是被托管的&#xff0c;另一個是沒有被托管的。但是&#xff0c;被托管的托管代碼是被誰管著呢&#xff1f;讓我們先來看看它們的定義。 托管代碼&#xff1a;由公共語言運行庫環境&#xff08;而…

如何實現前端新手引導功能?

大家好&#xff0c;我是若川。我持續組織了近一年的源碼共讀活動&#xff0c;感興趣的可以 點此掃碼加我微信 lxchuan12 參與&#xff0c;每周大家一起學習200行左右的源碼&#xff0c;共同進步。同時極力推薦訂閱我寫的《學習源碼整體架構系列》 包含20余篇源碼文章。歷史面試…

hp-ux鎖定用戶密碼_UX設計101:提出正確的問題-規劃和促進用戶訪談

hp-ux鎖定用戶密碼這是什么&#xff1f; (What is this?) This session is part of a learning curriculum that I designed to incrementally skill up and empower a team of Designers and Researchers whose skillset and ways of working needed to evolve to keep up wi…

我與掘金合作出了源碼共讀第一期,首發超400人報名,快來參與~

大家好&#xff0c;我是若川。最近有不少新朋友關注我。對我不是很了解的&#xff0c;或許可以讀我的2021年度總結。誠邀各位新老讀者朋友參加源碼共讀活動。同時我和掘金合作&#xff0c;共同出了源碼共讀第一期&#xff0c;11月25日——12月25日&#xff0c;獎品豐厚。我是前…

ASP.NET repeater添加序號列的方法

ASP.NET repeater添加序號列的方法 1、<itemtemplate> <tr><td> <%# Container.ItemIndex 1%> </td></tr> </itemtemplate> 2、<itemtemplate> <tr><td> <%# this.rpResult.Items.Count 1%> </td>&…

mac基本操作技巧_6個基本設計技巧

mac基本操作技巧“In everything you do, refine your skills and knowledge about fundamental concepts and simple cases. Once is never enough. As you revisit fundamentals, you will find new insights. It may appear that returning to basics is a step backward an…

如何突破技術瓶頸(適合P6以下)

大家好&#xff0c;我是若川。我持續組織了近一年的源碼共讀活動&#xff0c;感興趣的可以 點此掃碼加我微信 lxchuan12 參與&#xff0c;每周大家一起學習200行左右的源碼&#xff0c;共同進步。同時極力推薦訂閱我寫的《學習源碼整體架構系列》 包含20余篇源碼文章。歷史面試…

stack smash_扶手椅VGUX:Super Smash Bros.Ultimate

stack smashEasily far the most exciting news out of Super Smash Bros. Ultimate’s announcement was that every single character would be returning to the game.asily迄今為止最令人興奮的消息了任天堂明星大亂斗最終宣布的是&#xff0c; 每一個字符會被返回到游戲中…

《Two Dozen Short Lessons in Haskell》學習(十)- Private Definitions — the where-clause

《Two Dozen Short Lessons in Haskell》&#xff08;Copyright © 1995, 1996, 1997 by Rex Page&#xff0c;有人翻譯為Haskell二十四學時教程&#xff0c;該書如果不用于贏利&#xff0c;可以任意發布&#xff0c;但需要保留他們的copyright&#xff09;這本書是學習 Ha…

我和掘金合作的源碼共讀小冊報名快1000人了~

眾所周知&#xff0c;我和掘金合作出了源碼共讀第一期。我是前端領讀員。現在報名快1000人了~獎品豐厚。也有一些小伙伴已經寫了好幾期筆記了~但相對1000人寫的還是太少。什么&#xff1f;你不知道&#xff1f;那也很正常&#xff0c;畢竟我的公眾號常讀人數比較少。大部分人都…

【短語學習】盈余量分析(earned value analysis)

作者&#xff1a;gnuhpc 出處&#xff1a;http://www.cnblogs.com/gnuhpc/ 各種形式的盈余量分析是衡量執行時最常用的方法。它把范圍、成本和進度等度量標準結合在一起以幫助項目管理小組評估項目執行。對每項活動而言&#xff0c;盈余量分析包括計算三個主要數值&#xff1a;…