Note: This article is reproduced, but the content I have personally tried to confirm that the method is feasible, code a little change, reproduced for the preservation and sharing.
Original Author Address: http://gundumw100.iteye.com/blog/853967
Personal noise: It is said that Tabwidget is outdated, replaced by the fragment, but about this fragment temporarily have no time to discuss, is now using Tabwidget method, personal feeling realized the effect is very good.
Custom tabhost: Do not inherit tabactivity, the code is as follows:
Define layout file: Activity_main.xml
<?xml version= "1.0" encoding= "Utf-8"? ><tabhost xmlns:android= "Http://schemas.android.com/apk/res/android "Android:id=" @+id/tabhost01 "android:layout_width=" fill_parent "android:layout_height=" Fill_parent "> < LinearLayout android:layout_width= "fill_parent" android:orientation= "vertical" android:layout_height= "fill_parent "> <tabwidget android:id=" @android: Id/tabs "android:layout_width=" fill_parent "android:layout_height=" Wrap_ Content "/> <framelayout android:id=" @android: Id/tabcontent "android:layout_width=" Fill_parent "Android: layout_height= "Fill_parent" > <linearlayout android:id= "@+id/linearlayout1" android:layout_width= "Fill_ Parent "android:layout_height=" wrap_content "> <textview android:text=" "and" android:id= "@+id/textview02" Android:layout_width= "Fill_parent" android:layout_height= "wrap_content" > </TextView> </linearlayout > <linearlayout android:id= "@+id/linearlayout2" android:layout_width= "Fill_parent" android:layout_height= "WRap_content "> <scrollview android:id=" @+id/scroll01 "android:layout_width=" Fill_parent "Android:layout_ height= "fill_parent" android:scrollbars= "vertical" android:background= "@android: Color/white" > <linearlayout Android:layout_width= "Fill_parent" android:layout_height= "wrap_content" android:orientation= "Vertical" Android: padding= "2DP" > <textview android:id= "@+id/title01" android:layout_width= "Fill_parent" android:layout_height= "Wrap_content" android:gravity= "Center_horizontal" android:textsize= "20SP" android:text= "Employee information query test" android:padding = "5DP"/> <textview android:layout_width= "fill_parent" android:layout_height= "Wrap_content" android:padding= " 4DP "android:textsize=" 20sp "android:text=" test \ n test \ n test \ n test \ n test \ n test \ n test \ n test \ n test \ n test \ n test \ n test \ n test \ n test \ n test \ n Test \ \ n test \ ndo \ n test \ n test \ n test \ n test \ n test \ n Test \ n "android:layout_weight=" 1 "/> </LinearLayout> </ScrollView> </LinearLayout> <linearlayout android:id= "@+id/linearlayout3" android:layout_width="Wrap_content" android:layout_height= "wrap_content" > <textview android:text= "three" android:id= "@+id/ TextView03 "android:layout_width=" fill_parent "android:layout_height=" wrap_content "> </TextView> </ Linearlayout> </FrameLayout> </LinearLayout></TabHost>
Write Java code:
Package Com.example.test2;import Android.app.activity;import Android.os.bundle;import android.util.Log;import Android.view.layoutinflater;import Android.widget.tabhost;public class Mainactivity extends Activity {/** Called when The activity is first created. */Private Tabhost tabhost; @Override public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview ( R.layout.activity_main); try{tabhost = (tabhost) This.findviewbyid (r.id.tabhost01); Tabhost.setup (); Tabhost.addtab (Tabhost.newtabspec ("tab_1"). SetContent (R.ID.LINEARLAYOUT1)//.setindicator ("TAB1", This.getresources (). getdrawable (R.DRAWABLE.IMG01))); Setindicator ("TAB1")); Tabhost.addtab (Tabhost.newtabspec ("tab_2"). SetContent (R.ID.LINEARLAYOUT2)//.setindicator ("TAB2", This.getresources (). getdrawable (R.DRAWABLE.IMG01))); Setindicator ("TAB2")); Tabhost.addtab (Tabhost.newtabspec ("Tab_3"). SetContent (R.ID.LINEARLAYOUT3)//.setindicator ("TAB3", This.getresources (). getdrawable (R.DRAWABLE.IMG01)));. Setindicator ("TAB3")); Tabhost.setcurrenttab (1); }catch (Exception ex) {ex.printstacktrace (); LOG.D ("EXCEPTION", Ex.getmessage ()); } } }
Operation diagram:
I provide demo download: Click here to download demo
-Full-text end-
Android for paging (using Tabwidget/tabhost)