0.内容页没有采用常用的 fragment. 而是采用自认为更简单的直接继承方式。
1.使用继承来实现复用。
2.基类处理大页面布局和底部的导航显示以及逻辑。
3.采用线性布局。平分。tv居中。固定字体.
4.控件采用样式来集中属性。有分支的情况采用dranable 的selecter来处理。非常简洁明了。
视图布局 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:orientation="horizontal" android:id="@+id/bottomMenu" android:layout_width="match_parent" android:layout_height="56dp" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:paddingLeft="1dp" android:paddingRight="1dp"> <TextView android:id="@+id/TVmenuCategory1" style="@style/BottomMenu" android:drawableTop="@drawable/category" android:text="@string/bottomMenu1" /> <TextView android:id="@+id/TVmenuCategory2" style="@style/BottomMenu" android:drawableTop="@drawable/book" android:text="@string/bottomMenu2" /> <TextView android:id="@+id/TVmenuCategory3" style="@style/BottomMenu" android:drawableTop="@drawable/book" android:text="@string/bottomMenu3" /> <TextView android:id="@+id/TVmenuCategory4" style="@style/BottomMenu" android:drawableTop="@drawable/book" android:text="@string/bottomMenu4" /> <TextView android:id="@+id/TVmenuCategory5" style="@style/BottomMenu" android:drawableTop="@drawable/book" android:text="@string/bottomMenu5" /> </LinearLayout> <RelativeLayout android:id="@+id/RLayoutContent" android:layout_width="match_parent" android:layout_height="0dp" android:layout_above="@id/bottomMenu" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginLeft="0dp" android:layout_marginTop="0dp" android:layout_marginBottom="0dp"></RelativeLayout> </RelativeLayout> style 统一样式 & drawnable的selector来处理不同。 <!--页面master page --> <style name="BottomMenu"> <item name="android:gravity">center</item> <item name="android:layout_width">match_parent</item> <item name="android:layout_height">match_parent</item> <item name="android:layout_weight">1</item> <item name="android:textColor">@drawable/selector_bottommenu</item> </style> <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:color="@color/color_green" android:state_selected="true"/> <item android:color="@color/color_green" android:state_checked="true"/> <item android:color="@color/color_grey" /> </selector> activity. package com.android.linson.catshome.Control; import android.app.Activity; import android.os.Bundle; import android.support.annotation.Nullable; import android.util.Log; import android.view.View; import android.widget.RelativeLayout; import android.widget.TextView; import com.android.linson.catshome.R; //1.实现整体布局,留出主页面给派生类填充 。 //2.实现底部菜单功能 。底部逻辑全部在基类这里。 public class MasterPage extends Activity implements TextView.OnClickListener { //control private RelativeLayout mContent; private TextView mTVMenu1; private TextView mTVMenu2; private TextView mTVMenu3; private TextView mTVMenu4; private TextView mTVMenu5; //data private String TAG="DEBUG"; private TextView mSelectedMenu; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.masterpage); FindControls(); mSelectedMenu=mTVMenu1; FlushMenuSelected(); mTVMenu1.setOnClickListener(this); mTVMenu2.setOnClickListener(this); mTVMenu3.setOnClickListener(this); mTVMenu4.setOnClickListener(this); mTVMenu5.setOnClickListener(this); } private void FindControls() { mContent=findViewById(R.id.RLayoutContent); mTVMenu1=findViewById(R.id.TVmenuCategory1); mTVMenu2=findViewById(R.id.TVmenuCategory2); mTVMenu3=findViewById(R.id.TVmenuCategory3); mTVMenu4=findViewById(R.id.TVmenuCategory4); mTVMenu5=findViewById(R.id.TVmenuCategory5); } @Override public void onClick(View v) { if(v instanceof TextView) { TextView tempTV=(TextView)v; mSelectedMenu=tempTV; FlushMenuSelected(); switch (tempTV.getId()) { case R.id.TVmenuCategory1: { break; } } } } private void FlushMenuSelected() { mTVMenu1.setSelected(false); mTVMenu2.setSelected(false); mTVMenu3.setSelected(false); mTVMenu4.setSelected(false); mTVMenu5.setSelected(false); mSelectedMenu.setSelected(true); } }
原文地址:https://www.cnblogs.com/lsfv/p/9822562.html
时间: 2024-10-10 12:47:46