<?xml version=
"1.0"
encoding=
"utf-8"
?>
<RelativeLayout xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width=
"fill_parent"
android:layout_height=
"44dip"
android:gravity=
"center_vertical"
android:padding=
"0.0px"
>
<ImageView
android:id=
"@+id/rlCommenTitleBG"
android:layout_width=
"fill_parent"
android:layout_height=
"fill_parent"
android:background=
"@drawable/comm_title_bg"
/>
<TextView
android:id=
"@+id/ivTitleName"
style=
"@style/A1_Font"
android:layout_width=
"wrap_content"
android:layout_height=
"fill_parent"
android:layout_centerInParent=
"true"
android:ellipsize=
"end"
android:gravity=
"center"
android:paddingLeft=
"96.0dip"
android:paddingRight=
"96.0dip"
android:singleLine=
"true"
android:text=
"@string/app_name"
/>
<ImageButton
android:id=
"@+id/ivTitleBtnLeft"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_alignParentLeft=
"true"
android:layout_marginLeft=
"5dip"
android:layout_centerVertical=
"true"
android:background=
"@drawable/showleft_selector"
android:gravity=
"center"
android:includeFontPadding=
"false"
/>
<ImageButton
android:id=
"@+id/ivTitleBtnRigh"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_alignParentRight=
"true"
android:layout_centerVertical=
"true"
android:background=
"@drawable/showright_selector"
android:gravity=
"center"
android:layout_marginRight=
"5dip"
android:includeFontPadding=
"false"
/>
</RelativeLayout>
|
< LinearLayout xmlns:android ="http://schemas.android.com/apk/res/android" xmlns:tools ="http://schemas.android.com/tools" android:layout_width ="match_parent" android:layout_height ="match_parent" android:background ="@color/white" android:clickable ="true" android:orientation ="vertical" > <include layout= "@layout/main_title" android:focusable ="true" /> <FrameLayout android:id ="@+id/content_frame" android:layout_width ="match_parent" android:layout_height ="match_parent" /> </ LinearLayout>
public class MainActivity extends SlidingFragmentActivity implementsOnClickListener{ protected SlidingMenu mSlidingMenu ; private ImageButton ivTitleBtnLeft ; private Fragment mContent ; @Override public void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); initSlidingMenu(); setContentView(R.layout. activity_main ); initView(); } private void initView() { ivTitleBtnLeft = (ImageButton)this .findViewById(R.id. ivTitleBtnLeft); ivTitleBtnLeft .setOnClickListener( this); } //初始化左侧菜单 private void initSlidingMenu() { mContent = new Fragment_yixin(); getSupportFragmentManager() .beginTransaction() .replace(R.id. content_frame , mContent ) .commit(); setBehindContentView(R.layout. main_left_layout );//设置左边的菜单布局 FragmentTransaction mFragementTransaction = getSupportFragmentManager() .beginTransaction(); Fragment mFrag = new LeftSlidingMenuFragment(); mFragementTransaction.replace(R.id. main_left_fragment , mFrag); mFragementTransaction.commit(); mSlidingMenu = getSlidingMenu(); mSlidingMenu .setMode(SlidingMenu. LEFT); // 设置是左滑还是右滑,还是左右都可以滑,我这里只做了左滑 mSlidingMenu .setBehindOffsetRes(R.dimen. slidingmenu_offset); // 设置菜单宽度 mSlidingMenu .setFadeDegree(0.35f);// 设置淡入淡出的比例 mSlidingMenu .setTouchModeAbove(SlidingMenu. TOUCHMODE_FULLSCREEN); //设置手势模式 mSlidingMenu .setShadowDrawable(R.drawable. shadow); // 设置左菜单阴影图片 mSlidingMenu .setFadeEnabled( true); // 设置滑动时菜单的是否淡入淡出 mSlidingMenu .setBehindScrollScale(0.333f);// 设置滑动时拖拽效果 } @Override public void onClick(View v) { switch (v.getId()) { case R.id.ivTitleBtnLeft : //点击标题左边按钮弹出左侧菜单 mSlidingMenu .showMenu( true); break ; default : break ; } } /** * 左侧菜单点击切换首页的内容 */ public void switchContent(Fragment fragment) { mContent = fragment; getSupportFragmentManager() .beginTransaction() .replace(R.id. content_frame , fragment) .commit(); getSlidingMenu().showContent(); } }
左侧菜单: LeftSlidingMenuFragment
public class LeftSlidingMenuFragment extends Fragment implements OnClickListener{ private View yixinBtnLayout; //左侧菜单的易信功能 private View circleBtnLayout; //左侧菜单的朋友圈功能 private View settingBtnLayout; //左侧菜单的设置功能 @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.main_left_fragment, container, false); yixinBtnLayout = view.findViewById(R.id.yixinBtnLayout); yixinBtnLayout.setOnClickListener(this); circleBtnLayout = view.findViewById(R.id.circleBtnLayout); circleBtnLayout.setOnClickListener(this); settingBtnLayout = view.findViewById(R.id.settingBtnLayout); settingBtnLayout.setOnClickListener(this); System.out.println(); return view; } @Override public void onClick(View v) { Fragment newContent = null; switch (v.getId()) { case R.id.yixinBtnLayout: //易信的点击事件 newContent = new Fragment_yixin(); yixinBtnLayout.setSelected(true); circleBtnLayout.setSelected(false); settingBtnLayout.setSelected(false); break; case R.id.circleBtnLayout: //朋友圈的点击事件 newContent = new Fragment_friend(); yixinBtnLayout.setSelected(false); circleBtnLayout.setSelected(true); settingBtnLayout.setSelected(false); break; case R.id.settingBtnLayout: //设置的点击事件 newContent = new Fragment_setting(); yixinBtnLayout.setSelected(false); circleBtnLayout.setSelected(false); settingBtnLayout.setSelected(true); break; default: break; } if (newContent != null) switchFragment(newContent); } /* * 切换到不同的功能内容 */ private void switchFragment(Fragment fragment) { if (getActivity() == null) return; MainActivity ra = (MainActivity) getActivity(); ra.switchContent(fragment); } }
<? xml version ="1.0" encoding= "utf-8" ?> < FrameLayout xmlns:android ="http://schemas.android.com/apk/res/android" android:id ="@+id/main_left_fragment" android:layout_width ="match_parent" android:layout_height ="match_parent" android:background ="@color/white" > </ FrameLayout>
<? xml version ="1.0" encoding= "utf-8" ?> < ScrollView android:background ="@color/tools_box_bg" android:scrollbars ="none" android:layout_width ="fill_parent" android:layout_height ="fill_parent" xmlns:android ="http://schemas.android.com/apk/res/android" > <LinearLayout android:orientation= "vertical" android:id ="@+id/llRoot"android:layout_width ="fill_parent" android:layout_height ="wrap_content" > < com.chaowen.yixin.RoundedImageView android:layout_gravity ="center_horizontal" android:id ="@+id/headImageView" android:layout_width ="wrap_content" android:layout_height ="wrap_content" android:layout_marginTop = "25.0dip" android:src ="@drawable/head_default_yixin" android:adjustViewBounds = "true" android:maxHeight ="80dip" android:maxWidth= "80dip" /> < TextView android:textSize ="16.0sp" android:textColor ="#ffccccc6"android:layout_gravity ="center_horizontal" android:id ="@+id/nickNameTextView"android:layout_width ="wrap_content" android:layout_height ="wrap_content"android:layout_marginTop = "10.0dip" android:text ="511644784" /> < TextView android:textSize ="12.0sp" android:textColor ="#ffa8a8a3"android:layout_gravity ="center_horizontal" android:id ="@+id/yixinCodeTextView" android:layout_width ="wrap_content" android:layout_height ="wrap_content"android:layout_marginLeft = "10.0dip" android:layout_marginTop = "6.0dip"android:layout_marginRight = "10.0dip" android:layout_marginBottom = "10.0dip" /> < include android:id ="@+id/yixinBtnLayout" layout ="@layout/toolbox_item_yixin" /> < include android:id ="@+id/circleBtnLayout" layout ="@layout/toolbox_item_friend" /> < include android:id ="@+id/settingBtnLayout" layout ="@layout/toolbox_item_setting" /> < View android:background ="#ff1c1c1b" android:layout_width ="fill_parent" android:layout_height ="1.3299866dip" /> < View android:background ="#ff474745" android:layout_width ="fill_parent" android:layout_height ="1.0px" /> < TextView android:textSize ="12.0sp" android:textColor ="#ff999994"android:gravity ="center" android:layout_gravity ="bottom|center" android:id ="@+id/inviteFriendBtnLayout" android:background ="@drawable/tools_box_invite_btn_selector" android:layout_width= "wrap_content"android:layout_height ="wrap_content" android:layout_marginTop = "70.0dip"android:text ="邀请好友" /> </LinearLayout > </ ScrollView>