Mobile phone audio and video 2-Software Architecture Analysis, audio and video 2-Architecture Analysis
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: background = "# ff3097fd" android: gravity = "center_vertical" android: orientation = "horizontal"> <ImageView android: 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: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_marginLeft = "8dp" android: layout_weight = "1" android: background = "@ drawable/TV _search_bg_selector" android: clickable = "true" android: drawableLeft = "@ drawable/TV _search_drawable_selector" android: drawablePadding = "3dp" android: text = "Internet-wide 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" android: layout_height = "wrap_content" android: drawableLeft = "@ drawable/ic_topbanner_game"/> <ImageView android: layout_width = "6dp" android: layout_height = "6dp" android: layout_alignRight = "@ id/TV _game" android: background = "@ drawable/dot"/> </RelativeLayout> <ImageView android: id = "@ + id/iv_record" android: layout_marginLeft = "5dp" android: layout_marginRight = "8dp" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: src = "@ drawable/ic_topbanner_record"/> </com. atguigu. mobileplayer2.view. titleBar>
--------------------------------------- Android: drawableLeft = "@ drawable/sousuokuang_selector" sousuokuang_selector.xml corresponds to an image <? Xml version = "1.0" encoding = "UTF-8"?> <Selector xmlns: android = "http://schemas.android.com/apk/res/android"> <item android: state_pressed = "false" android: drawable = "@ drawable/ic_sousuokuang"/> <item android: state_pressed = "true" android: drawable = "@ drawable/ic_sousuokuang_press"/> </selector> ------ color --------- android: textColor = "@ drawable/sousuokuang_textcolor_selector" <? Xml version = "1.0" encoding = "UTF-8"?> <Selector xmlns: android = "http://schemas.android.com/apk/res/android"> <item android: state_pressed = "false" android: color = "#99 ffffff"/> <item android: state_pressed = "true" android: color = "# ffffffff"/> </selector> --------- search box background ---------- android: background = "@ drawable/search_bg_selector" <? Xml version = "1.0" encoding = "UTF-8"?> <Selector xmlns: android = "http://schemas.android.com/apk/res/android"> <item android: state_pressed = "false" android: drawable = "@ drawable/search_bg_normal"/> <item android: state_pressed = "true" android: drawable = "@ drawable/search_bg_press"/> </selector> android: drawable = "@ drawable/search_bg_normal" <? Xml version = "1.0" encoding = "UTF-8"?> <Shape xmlns: android = "http://schemas.android.com/apk/res/android" android: shape = "rectangle"> <corners android: radius = "12.0dp"/> <padding android: bottom = "5dp" android: left = "8dp" android: right = "8dp" android: top = "5dp"/> <solid android: color = "# ff2679ca"/> </shape> android: drawable = "@ drawable/search_bg_press" <? Xml version = "1.0" encoding = "UTF-8"?> <Shape xmlns: android = "http://schemas.android.com/apk/res/android" android: shape = "rectangle"> <corners android: radius = "12.0dp"/> <padding android: bottom = "5dp" android: left = "8dp" android: right = "8dp" android: top = "5dp"/> <solid android: color = "# cc2679ca"/> </shape> ----------- game ------------- android: background = "@ drawable/gam_dot"/> <? Xml version = "1.0" encoding = "UTF-8"?> <Shape xmlns: android = "http://schemas.android.com/apk/res/android" android: shape = "oval"> <solid android: color = "# ffff0000"/> </shape>
2. Customize 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 this class in code * @ param context */public TitleBar (Context context) {this (context, null );} /*** when this class is used in the layout file, Android uses this constructor to instantiate this class * @ param context * @ param attrs */public TitleBar (Context context, AttributeSet attrs) {this (context, attrs, 0);}/*** when you need to set a style, use this method * @ param context * @ param attrs * @ param defStyleAttr */public TitleBar (Context context, AttributeSet attrs, int defStyleAttr) {super (context, attrs, defStyleAttr ); this. context = context;}/*** call back this method when the layout file is loaded */@ Override protected void onFinishInflate () {super. onFinishInflate (); // get the child's instance 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 () {case 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: // The Playing History Toast. makeText (context, "playback History", Toast. LENGTH_SHORT ). show (); break ;}}}
3. Block repeated page initialization data
1. Add an ID field to BasePager
Public abstract class BasePager {/*** determine whether data has been initialized */public boolean isInit ;....}
2. shielding on the home page
/*** Get the instance view of a specific child * @ return */private BasePager getBasePager () {BasePager basePager = basePagers. get (position); if (basePager! = Null &&! BasePager. isInit) {basePager. initData (); basePager. isInit = true;} return basePager ;}