/** * 描述:设置绝对定位的主标题栏覆盖到内容的上边. * * @param overlay the new title bar overlay */ public void setTitleBarOverlay(boolean overlay) { ab_base.removeAllViews(); if (overlay) { RelativeLayout.LayoutParams layoutParamsFW1 = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); layoutParamsFW1.addRule(RelativeLayout.ABOVE, mAbBottomBar.getId()); ab_base.addView(contentLayout, layoutParamsFW1); RelativeLayout.LayoutParams layoutParamsFW2 = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); layoutParamsFW2.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE); ab_base.addView(mAbTitleBar, layoutParamsFW2); RelativeLayout.LayoutParams layoutParamsFW3 = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); layoutParamsFW3.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE); ab_base.addView(mAbBottomBar, layoutParamsFW3); } else { ab_base.addView( mAbTitleBar, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); RelativeLayout.LayoutParams layoutParamsFW2 = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); layoutParamsFW2.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE); ab_base.addView(mAbBottomBar, layoutParamsFW2); RelativeLayout.LayoutParams layoutParamsFW1 = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); layoutParamsFW1.addRule(RelativeLayout.BELOW, mAbTitleBar.getId()); layoutParamsFW1.addRule(RelativeLayout.ABOVE, mAbBottomBar.getId()); ab_base.addView(contentLayout, layoutParamsFW1); } }
/** * 描述:创建. * * @param savedInstanceState the saved instance state * @see android.support.v4.app.FragmentActivity#onCreate(android.os.Bundle) */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); mInflater = LayoutInflater.from(this); // 主标题栏 mAbTitleBar = new AbTitleBar(this); // 最外层布局 ab_base = new RelativeLayout(this); ab_base.setBackgroundColor(Color.rgb(255, 255, 255)); // 内容布局 contentLayout = new RelativeLayout(this); contentLayout.setPadding(0, 0, 0, 0); // 副标题栏 mAbBottomBar = new AbBottomBar(this); // 填入View ab_base.addView( mAbTitleBar, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); mAbTitleBar.setVisibility(View.GONE); RelativeLayout.LayoutParams layoutParamsBottomBar = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); layoutParamsBottomBar.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE); ab_base.addView(mAbBottomBar, layoutParamsBottomBar); RelativeLayout.LayoutParams layoutParamsContent = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); layoutParamsContent.addRule(RelativeLayout.BELOW, mAbTitleBar.getId()); layoutParamsContent.addRule(RelativeLayout.ABOVE, mAbBottomBar.getId()); ab_base.addView(contentLayout, layoutParamsContent); // Application初始化 abApplication = getApplication(); // 设置ContentView setContentView( ab_base, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); AbActivityManager.getInstance().addActivity(this); }