1. title bar
<?xml version= "1.0" encoding= "Utf-8"? ><com.atguigu.mobileplayer2.view.titlebar xmlns:android= "/http Schemas.android.com/apk/res/android "android:layout_width=" match_parent "android:layout_height=" 55DP "Android:bac Kground= "#ff3097fd" android:gravity= "center_vertical" android:orientation= "Horizontal" > <imageview a Ndroid:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:layout_marginleft= "8DP" android:src= "@drawable/ic_topbanner_logo"/> <textview android:id= "@+id/tv_search" android:layou T_width= "Wrap_content" android:layout_height= "wrap_content" android:layout_marginleft= "8DP" android:l ayout_weight= "1" android:background= "@drawable/tv_search_bg_selector" android:clickable= "true" Androi d:drawableleft= "@drawable/tv_search_drawable_selector" android:drawablepadding= "3DP" android:text= "full-screen search" Android:textcolor= "@drawable/tv_Search_textcolor_selector "android:textsize=" 14sp "/> <relativelayout android:id=" @+id/rl_game " Android:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:layout_marginleft= "5DP" > <textview android:id= "@+id/tv_game" android:layout_width= "Wrap_content" an droid:layout_height= "Wrap_content" android:drawableleft= "@drawable/ic_topbanner_game"/> <ImageVie W android:layout_width= "6DP" android:layout_height= "6DP" android:layout_alignright= "@id/t V_game "android:background=" @drawable/dot "/> </RelativeLayout> <imageview android:id= "@+id/iv_record" android:layout_marginleft= "5DP" android:layout_marginright= "8DP" Android:layout_widt H= "Wrap_content" android:layout_height= "wrap_content" android:src= "@drawable/ic_topbanner_record"/></ Com.atguigu.mobileplayer2.view. Titlebar>
2. Customizing the title bar
public class TitleBar extends LinearLayout implements View.onclicklistener {private View tv_search; Private View Rl_game; Private View Iv_record; Private context context; /** * Use this method when instantiating the class in code * @param context */public titlebar (context context) {this (context,null); /** * When using this class in a layout file, the Android system instantiates the class through this constructor method * @param context * @param attrs */public TitleBar (C Ontext context, AttributeSet attrs) {This (context, attrs,0); /** * When you need to set a style, you can use this method * @param context * @param attrs * @param defstyleattr */Public Title Bar (context context, AttributeSet attrs, int defstyleattr) {Super (context, attrs, defstyleattr); This.context = context; }/** * Callback This method when the layout file is loaded */@Override protected void Onfinishinflate () {super.onfinishinflate () ; Get the child's example tv_search = Getchildat (1); Rl_game = Getchildat (2); Iv_record = Getchildat(3); Set the Click event Tv_search.setonclicklistener (this); Rl_game.setonclicklistener (this); Iv_record.setonclicklistener (this); } @Override public void OnClick (View v) {switch (V.getid ()) {r.id.tv_search://Search// Toast.maketext (Context, "search", Toast.length_short). Show (); Intent Intent = new Intent (context,searchactivity.class); Context.startactivity (Intent); Break Case r.id.rl_game://Game Toast.maketext (context, "game", Toast.length_short). Show (); Break Case r.id.iv_record://Play History toast.maketext (context, "Play history", Toast.length_short). Show (); Break } }}
3. Block each page to repeat the initialization of the data
1. Add an identity field to the Basepager
Public abstract class Basepager { /** * Determines whether data is initialized/ public boolean isinit; ....}
2. Block in the main page
/** * Get a specific instance view of a child * @return */private Basepager Getbasepager () { Basepager Basepager = basepagers.get (position);
if (Basepager! = null&&!basepager.isinit) { basepager.initdata (); Basepager.isinit = true; } return Basepager;}
Software architecture analysis of mobile audio and video 2--