Cultivation-------------Android tabhost,tabwidget Tab summarizes Android Tabhosttabhost, personally understood as a tab container, is a special framelayout layout (frame layout) According to the SDK documentation , Container for a tabbed window view. This object holds the CHILDREN:A set of tab labels, the user clicks to select a specific tab, and a framelayout objec T that displays the contents of the page. The individual elements is typically controlled using this container object, rather than setting values on the child Elem Ents themselves. Tabhost mainly consists of two parts, the label and the content, wherein the content is a framelayout, when the user clicks on a different label can display different content. The use of labels can achieve the effect of paging, is the content of the page richer, more affinity, of course, at the same time, it will also increase the complexity of the page. A simple tabhost layout 1. Inherit TabActivity2 first. Through Tabactivity Gettabhost ( ) method to get a Tabhost object 3. Defines the contents of the tab (which is a Framelayout object) and binds to Tabhost to bind the contents of the Tabhost container through a statement layoutinflater.from (this). Inflate (R.layout.main, Tabhost.gettabcontentview (), true); 4. Add tab and SET options title and content we know that adding a tab requires specifying a Tabspec object, It is available through the Tabhost newtabspec (tab identification), and you can set the title of the tab (you can set the picture) and set the tab contents, such as tabhost.addtab (Tabhost.newtabspec ("Tab01") .setindicator ("Label 1", Getresources (). getdRawable (R.drawable.icon)) .setcontent (R.ID.TAB01));.: Source: Tabtest01.zip (43.15 KB, downloaded: 4) Beginners Note: if Setcontentview (R.layout.main), which inherits from the Tabactivity class, can cause an error, possibly because the main layout file is set incorrectly (explained below). The workaround is to first remove this line above in the example above tabhost is just bound to a layout container, which means that the contents of each tab are written in a layout file, The contents of each tab are then distinguished by different IDs. If the number of tabs is too large, or the layout of each tab is more complex, it is bound to make the layout container appear bloated and poor readability, not conducive to later maintenance. Available in Android We can also specify the content source for each tab via SetContent (Intent Intent): Sometimes we need to personalize the title of the tab, although we know Setindicator () Method can set the title of the tab when you can specify the picture, but all the pictures in the bottom, the text above the picture, can we set the text in the picture below, or the text on the right side of the picture? Of course, the Setindicator () method in Android has the following three types: Tabhost.tabspec Setindicator (charsequence label) Tabhost.tabspec s Etindicator (charsequence label, drawable icon) tabhost.tabspec setindicator (view view) The first two don't say , presumably now everyone is familiar with it. Mainly say the third, the third, the method parameter is a view, presumably you want to know some of the strange. Okay, no more nonsense. Source code:: Tabtest03.zip (51.65 KB, download count: 3) Android's tabwidget above basically has explained most of the usage of Tabhost in Android, but not enough. In development, we sometimes need more practical tabhost, although we can set TABhost, but we will certainly find that in the example above, the label is on the top, then how to let the label in the following? The following describes Tabwidget according to the SDK documentation, displays a list of tab labels representing Each page in the parent ' s tab collection. The container object for this widget is tabhost. When the user selects a tab, this object sends a message to the parent container, tabhost, to-tell it to switch the DISPLA Yed page. You typically won ' t use many methods directly on the This object. The container tabhost is a used to add labels, add the callback handler, and manage callbacks. You might call this object to iterate the list of tabs, or to tweak the layout of the tab list, but most methods should is Called on the containing Tabhost object. We can roughly understand that Tabwidget is a collection of tabs, which is the label bar. According to the above beginner Note: Do not randomly set the Setcontentview ( R.layout.main), this statement may cause an error. If you set this statement, then the main layout file will be configured correctly. How to define the Main.xml layout file correctly? First we need to figure out the relationship between Tabhost,tabwidget,framelayout, we know that tabhost is like a tab container, including the contents of multiple tabs and tabs, where the contents of the tab are a Framelayout container, Tabwidget can be understood as a tab bar. The correct main.xml file should contain these three components tabhost,tabwidget,framelayout and the IDs of the three components must be @andrOid:id/tabhost, @android: Id/tabs, @android: Id/tabcontent as follows, <?xml version= "1.0" encoding= "Utf-8"? ><tabhost xmlns:android= "Http://schemas.android.com/apk/res/android" android:id= "@android: ID/ Tabhost " android:layout_width=" match_parent " android:layout_height=" Match_parent "> <linearlayout android:orientation= "vertical" android:layout_width= "fill_parent" android:layout_height= "Fill_parent" > <TabWidget android:id= "@ Android:id/tabs " android:layout_width=" Fill_parent " android:layout_height= "Wrap_conTent > </TabWidget> &NBSP ; <FrameLayout android:id= "@android: Id/tabcontent" android:layout_width= "fill_parent " android:layout_height=" fill_content " android:padding= "5DP"/> </LinearLayout> </tabhost : Using the Tabwidget tab bar at the top source: Tabtest04.zip (53.09 KB, Downloads: 1) If you want the tab bar to be below, you only need to swap tabwidget and framelayout locations, such as < XML version= "1.0" encoding= "Utf-8"? ><tabhost xmlns:android= "http://schemas.android.com/apk/res/ Android " android:id=" @android: Id/tabhost " android:layout_width=" Match_parent " android:layout_height= "Match_parent" > <linearlayout android:orientation= "vertical" android: Layout_width= "Fill_parent" android:layout_height= "Fill_parent" > <FrameLayout android:id= "@android: id/tabcontent" android:layout_width= "fill_parent" android:layout_height= "Fill_ Parent " android:layout_weight=" 1.0 " android:padding= "5DP"/> <tabwidge t android:id= "@android: Id/tabs" & nbsp; Android:layout_Width= "Fill_parent" android:layout_height= "Wrap_ Content "> </TabWidget> </ linearlayout> </tabhost>: Using the Tabwidget tab bar under source code: Tabtest05.zip (150.63 KB, Downloads: 7) notice, Framelayout a row android:layout_weight= "1.0" Statement this property represents the specific gravity, all components of Android default this property is 0, meaning they only show on the screen they need space size. If this property is set, activity will scale the size of the space according to the set value for example, if there are three components in the acitivity, assuming that the screen height is 90cm, three components if the property is set to 0, then they will be displayed in the normal way on the screen. If the first component setting component is set to 0 and the remaining two components are set to 1, then this screen will be displayed in 0:1:1 mode, and if the first component defaults to 10cm, the other two components account for 40cm
Cultivation-------------Android tabhost,tabwidget Tab Summary