This example describes the Tabhost usage of the Android control. Share to everyone for your reference. Specifically as follows:
The following Tabhost implements the Android tab.
Main.xml Layout file:
<?xml version= "1.0" encoding= "Utf-8"?> <linearlayout xmlns:android= "http://schemas.android.com/apk/res/" Android "Android:layout_width=" Fill_parent "android:layout_height=" fill_parent "> <linearlayout android:id=" @ +id/tab01 "android:layout_width=" fill_parent "android:layout_height=" fill_parent "android:gravity=" Center_
Horizontal "android:orientation=" vertical > <imageview android:id= "@+id/iv01" android:scaletype= "FitXY" android:layout_gravity= "center" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" Andr oid:src= "@drawable/andy"/> <textview android:id= "@+id/tv01" android:layout_width= "Wrap_content" android:l ayout_height= "Wrap_content" android:textsize= "24dip" android:text= "Android Creator: Andy Rubin"/> </linearlayout > <linearlayout android:id= "@+id/tab02" android:layout_width= fill_parent "android:layout_height=" Fill_ Parent "android:gravity=" Center_horizontal "Android:orientation= "vertical" > <imageview android:id= "@+id/iv02" android:scaletype= "Fitxy" Android:layout_gravit y= "center" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:src= "@drawable/bil L "/> <textview android:id=" @+id/tv02 "android:layout_width=" wrap_content "android:layout_height=" Wrap_con Tent "android:textsize=" 24dip "android:text=" One of Java creators: Bill Joy "/> </LinearLayout> <linearlayout Andr Oid:id= "@+id/tab03" android:layout_width= "fill_parent" android:layout_height= "Fill_parent" android:gravity= " Center_horizontal "android:orientation=" vertical "> <imageview android:id=" @+id/iv03 "android:scaletype=" fit
XY "android:layout_gravity=" center "android:layout_width=" wrap_content "android:layout_height=" Wrap_content "
android:src= "@drawable/torvalds"/> <textview android:id= "@+id/tv03" android:layout_width= "Wrap_content" Android:layout_height= "Wrap_coNtent "android:textsize=" 24dip "android:text=" father of Linux: Linus Torvalds "/> </LinearLayout> </linearlayout
>
Tabhostactivity class:
Package com.ljq.activity;
Import android.app.TabActivity;
Import Android.os.Bundle;
Import Android.view.LayoutInflater;
Import Android.widget.TabHost;
public class Tabhostactivity extends tabactivity{
private tabhost tab=null;
@Override public
void OnCreate (Bundle savedinstancestate) {
super.oncreate (savedinstancestate);
Tab=this.gettabhost ();
Layoutinflater.from (This). Inflate (R.layout.main, Tab.gettabcontentview (), true);
Tab.addtab (Tab.newtabspec ("tab One"). Setindicator ("tab One",
getresources (). getdrawable (R.drawable.png1)). SetContent (R.ID.TAB01));
Tab.addtab (Tab.newtabspec ("tab Two"). Setindicator ("tab Two",
getresources (). getdrawable (R.drawable.png2)). SetContent (R.ID.TAB02));
Tab.addtab (Tab.newtabspec ("tab three"). Setindicator ("tab three",
getresources (). getdrawable (R.drawable.png3)). SetContent (R.ID.TAB03));
}
Run Result:
I hope this article will help you with your Android program.