The main interface layout is as follows
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "android:orientation=" vertical "android:layout_width=" Fill_parent "Android: layout_height= "Fill_parent" android:background= "@drawable/f_home_boungroud" > <include Andro Id:id= "@+id/titlebar" layout= "@layout/titlebar"/>//TitleBar <framelayout android:id= "@+id/tab_conten T "main interface content framelayout android:layout_width=" fill_parent "android:layout_height=" 0DP "Android oid:layout_weight= "1.0"/> <radiogroup android:id= "@+id/tabs_rg" under the main interface four tab buttons Android:layout_width= "Fill_parent" android:layout_height= "50DP" android:orientation= "Horizontal" android:gravity= "center" android:background= "@drawable/downbar" > <radiobutt On android:id= "@+id/Tab_rb_a "android:layout_width=" 0DP "android:layout_height=" Wrap_content "and roid:drawabletop= "@drawable/selector_tab" android:button= "@null" android:text= "boutique" android:layout_margintop= "2DP" android:layout_marginbottom= "2DP" android:textcolor= "@a Ndroid:color/white "android:textsize=" 13sp "android:layout_weight=" 1.0 "Andro id:gravity= "Center" android:singleline= "true" android:checked= "true" Android:ba ckground= "@drawable/selector_tab_item"/> <radiobutton android:id= "@+id/tab_rb_ B "Android:layout_width=" 0DP "android:layout_height=" Wrap_content "android:dr awabletop= "@drawable/selector_tab2" android:button= "@null" android:text= "Hot List" Android:layout_margintop= "2DP" android:layout_marginbottom= "2DP" android:textcolor= "@android: Color/white" Android:textsize= "13SP" android:layout_weight= "1.0" android:gravity= "center" Android:singleline= "true" android:background= "@drawable/selector_tab_item"/> <radiobutton android:id= "@+id/tab_rb_c" android:layout_width= "0DP" a ndroid:layout_height= "Wrap_content" android:drawabletop= "@drawable/selector_tab3" Android:bu tton= "@null" android:text= "Software" android:textcolor= "@android: Color/white" Androi D:textsize= "13SP" android:layout_weight= "1.0" android:gravity= "Center" Androi D:singleline= "true" android:layout_margintop= "2DP" android:layout_marginbottom= "2DP" Android:background= "@drawable/selector_tab_item"/> <radiobutton android:id= "@+id/tab_rb_ D "Android:layout_width=" 0DP "android:layout_height=" Wrap_content "android:dr awabletop= "@drawable/selector_tab4" android:button= "@null" android:text= "Game" a Ndroid:textcolor= "@android: Color/white" android:textsize= "13sp" android:layout_weight= "1.0" android:gravity= "Center" android:singleline= "true" Android:layout_marg intop= "2DP" android:layout_marginbottom= "2DP" android:background= "@drawable/selector_tab_ite M "/> </RadioGroup></LinearLayout>
/**
* Get a picture of fragmenttransaction
*
* @param index
* @return
*/
Private fragmenttransaction obtainfragmenttransaction (int index) {
Fragmenttransaction ft = Childfragmentmanager
. BeginTransaction ();
Set Toggle Animations
if (Index > Currenttab) {
Ft.setcustomanimations (r.anim.slide_left_in, r.anim.slide_left_out);
} else {
Ft.setcustomanimations (r.anim.slide_right_in,
R.anim.slide_right_out);
}
return ft;
}
Show or hide fragment by clicking the tab button
private void ShowTab (int idx) {
for (int i = 0; i < fragments.size (); i++) {
Fragment Fragment = Fragments.get (i);
Fragmenttransaction ft = obtainfragmenttransaction (IDX);
if (idx = = i) {
Ft.show (fragment); Get the corresponding click button to show the different fragment
} else {
Ft.hide (fragment);
}
Ft.commit ();
}
Currenttab = idx; Update Target tab to current tab
}
When we, the fragment hidden, we let him pause, show, we let him resume, we can easily do adapter.notifidatachanget here () to do some other updates or initialization operations
public void Selete (int i) {
Fragment Fragment = Fragments.get (i);
Fragmenttransaction ft = obtainfragmenttransaction (i);
Getcurrentfragment (). OnPause (); Pause the current tab
if (fragment.isadded ()) {
Fragment.onresume (); Onresume () to start the Target tab
} else {
Ft.add (Fragmentcontentid, fragment);
}
ShowTab (i); Show Target Tab
Ft.commit ();
If you set the Toggle Tab Extras feature Interface
// if (null! = Onrgsextracheckedchangedlistener) {
// Onrgsextracheckedchangedlistener.onrgsextracheckedchanged (
// Radiogroup, Checkedid, i);
// }
}
The entire page tab is through, show and hide fragment to achieve the tab page switch, the implementation principle is relatively simple.
[Application--Second main interface Tab] Rapid development of Android application market