﻿{"id":1775,"date":"2012-02-09T16:47:38","date_gmt":"2012-02-09T08:47:38","guid":{"rendered":"http:\/\/blog.jixin.ntxz.net\/?p=1775"},"modified":"2012-02-09T16:47:38","modified_gmt":"2012-02-09T08:47:38","slug":"android%e5%ae%9e%e7%8e%b0%e7%95%8c%e9%9d%a2%e5%ba%95%e9%83%a8%e7%9a%84tab","status":"publish","type":"post","link":"http:\/\/www.ntxz.net\/?p=1775","title":{"rendered":"Android\u5b9e\u73b0\u754c\u9762\u5e95\u90e8\u7684tab"},"content":{"rendered":"<p>\u9ed8\u8ba4\u7684tabhost\u4e2d\u7684tabwidget\u662f\u653e\u5728\u9876\u90e8\u7684\uff0c\u6709\u65f6\u9700\u8981\u5c06TAB\u79fb\u5230\u5e95\u90e8\u6765\uff0c\u8fd9\u65f6\u9700\u8981\u5728XML\u4e2d\u505a\u4e9b\u7ec6\u5fae\u7684\u53d8\u52a8\uff0c\u5982\u4e0b\uff1a<\/p>\n<pre class=\"brush: xml\">\r\n&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;\r\n&lt;LinearLayout\r\n\txmlns:android=&quot;http:\/\/schemas.android.com\/apk\/res\/android&quot;\r\n\tandroid:orientation=&quot;vertical&quot;\r\n\tandroid:layout_width=&quot;fill_parent&quot;\r\n\tandroid:layout_height=&quot;fill_parent&quot;&gt;\r\n\t&lt;TabHost\r\n\t\tandroid:id=&quot;@+id\/tabhost&quot;\r\n\t\tandroid:layout_width=&quot;fill_parent&quot;\r\n\t\tandroid:layout_height=&quot;fill_parent&quot;&gt;\r\n\t\t&lt;FrameLayout\r\n\t\t\tandroid:id=&quot;@android:id\/tabcontent&quot;\r\n\t\t\tandroid:layout_width=&quot;fill_parent&quot;\r\n\t\t\tandroid:layout_height=&quot;fill_parent&quot;\r\n\t\t\tandroid:paddingBottom=&quot;62px&quot;&gt;\r\n\t\t\t&lt;AnalogClock\r\n\t\t\t\tandroid:id=&quot;@+id\/tab1&quot;\r\n\t\t\t\tandroid:layout_width=&quot;fill_parent&quot;\r\n\t\t\t\tandroid:layout_height=&quot;fill_parent&quot;\r\n\t\t\t\tandroid:layout_centerHorizontal=&quot;true&quot; \/&gt;\r\n\t\t\t&lt;Button\r\n\t\t\t\tandroid:id=&quot;@+id\/tab2&quot;\r\n\t\t\t\tandroid:layout_width=&quot;fill_parent&quot;\r\n\t\t\t\tandroid:layout_height=&quot;fill_parent&quot;\r\n\t\t\t\tandroid:text=&quot;A semi-random button&quot; \/&gt;\r\n\t\t&lt;\/FrameLayout&gt;\r\n\t\t&lt;RelativeLayout\r\n\t\t\tandroid:layout_width=&quot;fill_parent&quot;\r\n\t\t\tandroid:layout_height=&quot;fill_parent&quot;&gt;\r\n\t\t\t&lt;TabWidget\r\n\t\t\t\tandroid:id=&quot;@android:id\/tabs&quot;\r\n\t\t\t\tandroid:layout_alignParentBottom=&quot;true&quot;\r\n\t\t\t\tandroid:layout_width=&quot;fill_parent&quot;\r\n\t\t\t\tandroid:layout_height=&quot;60px&quot; \/&gt;\r\n\t\t&lt;\/RelativeLayout&gt;\r\n\t&lt;\/TabHost&gt;\r\n&lt;\/LinearLayout&gt;\r\n<\/pre>\n<p>\u6211\u4eec\u5c06tabWidget\u653e\u5230\u4e00\u4e2arelativeLayout\u4e2d\uff0c\u7136\u540e\u52a0\u4e0a\u8fd9\u53e5android:layout_alignParentBottom=&#8221;true&#8221;\uff0c\u4ee3\u7801\u5b9e\u73b0\u5982\u4e0b\uff1a<\/p>\n<pre class=\"brush: java\">\r\npublic class TabTest2 extends Activity {\r\n\tpublic void onCreate(Bundle icicle) {\r\n\t\tsuper.onCreate(icicle);\r\n\t\tsetContentView(R.layout.tabtest2);\r\n\t\tTabHost tabs=(TabHost)findViewById(R.id.tabhost);\r\n\t\t\r\n\t\ttabs.setup();\r\n\t\t\r\n\t\tTabHost.TabSpec spec=tabs.newTabSpec(&quot;tag1&quot;);\r\n\t\tspec.setContent(R.id.tab1);\r\n\t\tspec.setIndicator(&quot;Clock&quot;);\r\n\t\ttabs.addTab(spec);\r\n\t\t\r\n\t\tspec=tabs.newTabSpec(&quot;tag2&quot;);\r\n\t\tspec.setContent(R.id.tab2);\r\n\t\tspec.setIndicator(&quot;Button&quot;);\r\n\t\ttabs.addTab(spec);\r\n\t\t\r\n\t\ttabs.setCurrentTab(0);\r\n\t}\r\n}\r\n<\/pre>\n<p>\u8fd9\u6837\u5c31\u53ef\u4ee5\u628atab\u7f6e\u4e8e\u9875\u9762\u5e95\u90e8\u4e86\uff0c\u5176\u5b9e\u8ddf\u4e0a\u6b21\u8bb2\u7684LinearLayout\u7684buttonBar\u6837\u5f0f\u6709\u70b9\u7c7b\u4f3c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9ed8\u8ba4\u7684tabhost\u4e2d\u7684tabwidget\u662f\u653e\u5728\u9876\u90e8\u7684\uff0c\u6709\u65f6\u9700\u8981\u5c06TAB\u79fb\u5230\u5e95\u90e8\u6765\uff0c\u8fd9\u65f6\u9700\u8981\u5728XML\u4e2d\u505a\u4e9b\u7ec6\u5fae [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[346],"tags":[597,504],"class_list":["post-1775","post","type-post","status-publish","format-standard","hentry","category-android","tag-android","tag-tab"],"views":480,"_links":{"self":[{"href":"http:\/\/www.ntxz.net\/index.php?rest_route=\/wp\/v2\/posts\/1775","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.ntxz.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.ntxz.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.ntxz.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.ntxz.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1775"}],"version-history":[{"count":1,"href":"http:\/\/www.ntxz.net\/index.php?rest_route=\/wp\/v2\/posts\/1775\/revisions"}],"predecessor-version":[{"id":1776,"href":"http:\/\/www.ntxz.net\/index.php?rest_route=\/wp\/v2\/posts\/1775\/revisions\/1776"}],"wp:attachment":[{"href":"http:\/\/www.ntxz.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1775"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.ntxz.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1775"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.ntxz.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1775"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}