不扯闲话了,直接进入正题吧
frame_content.xml
[html] view plain co
- <?xml version="1.0" encoding="utf-8"?>
- <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/content"
- android:layout_width="match_parent"
- android:layout_height="match_parent" />
frame_left_menu.xml
[html] view plain cop
- <?xml version="1.0" encoding="utf-8"?>
- <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/left_menu"
- android:layout_width="match_parent"
- android:layout_height="match_parent" />
frame_right_menu.xml
[html] view plain co
- <?xml version="1.0" encoding="utf-8"?>
- <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/right_menu"
- android:layout_width="match_parent"
- android:layout_height="match_parent" />
在 主Activity 初始化 SlidingMenu
[java] view plain co
- package
- import
- import
- import
- import
- import
- import
- import
- import
- import
- import
- import
- import
- import
- import
- import
- import
- import
- import
- import
- import
- public class MainActivity extends SlidingFragmentActivity implements
- private
- @SuppressLint("NewApi")
- @Override
- public void
- super.onCreate(savedInstanceState);
- "Home");
- // setTitle(R.string.sliding_title);
- setContentView(R.layout.frame_content);
- //set the Behind View
- setBehindContentView(R.layout.frame_left_menu);
- // customize the SlidingMenu
- mSlidingMenu = getSlidingMenu();
- //设置左右都可以划出SlidingMenu菜单
- //设置右侧菜单的布局文件
- mSlidingMenu.setSecondaryShadowDrawable(R.drawable.drawer_shadow);
- // mSlidingMenu.setShadowWidth(5);
- // mSlidingMenu.setBehindOffset(100);
- //设置阴影图片
- //设置阴影图片的宽度
- //SlidingMenu划出时主页面显示的剩余宽度
- 0.35f);
- //设置SlidingMenu 的手势模式
- //TOUCHMODE_FULLSCREEN 全屏模式,在整个content页面中,滑动,可以打开SlidingMenu
- //TOUCHMODE_MARGIN 边缘模式,在content页面中,如果想打开SlidingMenu,你需要在屏幕边缘滑动才可以打开SlidingMenu
- //TOUCHMODE_NONE 不能通过手势打开SlidingMenu
- mSlidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
- //设置 SlidingMenu 内容
- FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
- new
- new
- new
- fragmentTransaction.commit();
- //使用左上方icon可点,这样在onOptionsItemSelected里面才可以监听到R.id.home
- true);
- // getActionBar().setLogo(R.drawable.ic_logo);
- }
- @Override
- public boolean
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.main, menu);
- return true;
- }
- @Override
- public boolean
- switch
- case
- //动态判断自动关闭或开启SlidingMenu
- // getSlidingMenu().showMenu();//显示SlidingMenu
- // getSlidingMenu().showContent();//显示内容
- return true;
- case
- Toast.makeText(getApplicationContext(), R.string.refresh, Toast.LENGTH_SHORT).show();
- return true;
- case
- if(mSlidingMenu.isSecondaryMenuShowing()){
- mSlidingMenu.showContent();
- else{
- mSlidingMenu.showSecondaryMenu();
- }
- return true;
- default:
- return super.onOptionsItemSelected(item);
- }
- }
- @SuppressLint("NewApi")
- @Override
- public void selectItem(int
- // update the main content by replacing fragments
- null;
- switch
- case 0:
- new
- break;
- case 1:
- new
- break;
- case 2:
- new
- break;
- case 3:
- new
- break;
- case 4:
- new
- break;
- case 5:
- new
- break;
- default:
- break;
- }
- if (fragment != null) {
- FragmentManager fragmentManager = getSupportFragmentManager();
- fragmentManager.beginTransaction()
- .replace(R.id.content, fragment).commit();
- // update selected item and title, then close the drawer
- setTitle(title);
- mSlidingMenu.showContent();
- else
- // error in creating fragment
- "MainActivity", "Error in creating fragment");
- }
- }
- }
左边SlidingMenu Fragment
[java] view plain cop
- package
- import
- import
- import
- import
- import
- import
- import
- import
- import
- import
- import
- import
- import
- import
- public class MenuFragment extends Fragment implements
- private
- private
- private
- private
- private
- private
- private int selected = -1;
- @Override
- public void
- try
- mCallback = (SLMenuListOnItemClickListener) activity;
- catch
- throw new
- " must implement OnResolveTelsCompletedListener");
- }
- super.onAttach(activity);
- }
- @Override
- public void
- // TODO Auto-generated method stub
- super.onCreate(savedInstanceState);
- }
- @Override
- public
- Bundle savedInstanceState) {
- null);
- findView(rootView);
- return
- }
- private void
- mDrawerList = (ListView) rootView.findViewById(R.id.left_menu);
- mNavMenuTitles = getResources().getStringArray(R.array.nav_drawer_items);
- // nav drawer icons from resources
- mNavMenuIconsTypeArray = getResources()
- .obtainTypedArray(R.array.nav_drawer_icons);
- new
- // adding nav drawer items to array
- // Home
- new NavDrawerItem(mNavMenuTitles[0], mNavMenuIconsTypeArray
- 0, -1)));
- // Find People
- new NavDrawerItem(mNavMenuTitles[1], mNavMenuIconsTypeArray
- 1, -1)));
- // Photos
- new NavDrawerItem(mNavMenuTitles[2], mNavMenuIconsTypeArray
- 2, -1)));
- // Communities, Will add a counter here
- new NavDrawerItem(mNavMenuTitles[3], mNavMenuIconsTypeArray
- 3, -1), true, "22"));
- // Pages
- new NavDrawerItem(mNavMenuTitles[4], mNavMenuIconsTypeArray
- 4, -1)));
- // What's hot, We will add a counter here
- new NavDrawerItem(mNavMenuTitles[5], mNavMenuIconsTypeArray
- 5, -1), true, "50+"));
- // Recycle the typed array
- mNavMenuIconsTypeArray.recycle();
- // setting the nav drawer list adapter
- new
- mNavDrawerItems);
- mDrawerList.setAdapter(mAdapter);
- this);
- if(selected!=-1){
- true);
- mDrawerList.setSelection(selected);
- else{
- 0, true);
- 0);
- }
- }
- @Override
- public void onItemClick(AdapterView<?> parent, View view, int
- long
- // update selected item and title, then close the drawer
- true);
- mDrawerList.setSelection(position);
- if(mCallback!=null){
- mCallback.selectItem(position, mNavMenuTitles[position]);
- }
- selected = position;
- }
- /**
- * 左侧菜单 点击回调接口
- * @author FX_SKY
- *
- */
- public interface
- public void selectItem(int
- }
- }
MenuFragment 布局文件fragment_menu.xml
[html] view plain co
- <?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" >
- <ListView
- android:id="@+id/left_menu"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_gravity="start"
- android:choiceMode="singleChoice"
- android:divider="@android:color/transparent"
- android:dividerHeight="0dp"
- android:background="#111"/>
- </RelativeLayout>
右边SlidingMenu Fragment
[java] view plain cop
- package
- import
- import
- import
- import
- import
- import
- import
- public class RightMenuFragment extends
- @Override
- public void
- super.onAttach(activity);
- }
- @Override
- public void
- // TODO Auto-generated method stub
- super.onCreate(savedInstanceState);
- }
- @Override
- public
- Bundle savedInstanceState) {
- null);
- findView(rootView);
- return
- }
- private void
- }
- }
RightMenuFragment 布局文件 fragment_right_menu.xml
[html] view plain cop
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical"
- android:background="#464646">
- <!-- 顶部个人基本信息 -->
- <RelativeLayout
- android:layout_width="fill_parent"
- android:layout_height="70dip">
- <ImageView
- android:id="@+id/right_permsg_center_img_usericon"
- android:layout_width="60dip"
- android:layout_height="60dip"
- android:layout_marginLeft="5dip"
- android:layout_marginTop="5dip"
- android:layout_marginBottom="5dip"
- android:src="@drawable/night_biz_pc_account_avatar_bg"
- android:scaleType="fitXY"/>
- <TextView
- android:id="@+id/right_permsg_center_tv_name"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="AABBV"
- android:layout_toRightOf="@id/right_permsg_center_img_usericon"
- android:layout_marginLeft="10dip"
- android:textColor="@color/whilte"
- android:textSize="15sp"
- android:layout_marginTop="13dip"/>
- <ImageView
- android:id="@+id/right_permsg_center_img_icon"
- android:layout_width="15dip"
- android:layout_height="15dip"
- android:scaleType="fitXY"
- android:layout_toRightOf="@id/right_permsg_center_img_usericon"
- android:layout_below="@id/right_permsg_center_tv_name"
- android:src="@drawable/biz_pc_main_money_icon"
- android:layout_alignLeft="@id/right_permsg_center_tv_name"/>
- <TextView
- android:id="@+id/right_permsg_center_tv_level"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_below="@id/right_permsg_center_tv_name"
- android:layout_toRightOf="@id/right_permsg_center_img_icon"
- android:text="科长"
- android:textColor="@color/whilte"
- android:layout_marginLeft="5dip"
- android:textSize="10sp"
- android:layout_alignBaseline="@id/right_permsg_center_img_icon"
- android:layout_marginTop="2dip"/>
- <ImageButton
- android:id="@+id/right_permsg_center_imgbtn_select"
- android:layout_width="30dip"
- android:layout_height="30dip"
- android:layout_alignParentRight="true"
- android:layout_marginRight="10dip"
- android:background="@drawable/app_recommend_arrow"
- android:layout_centerVertical="true"/>
- </RelativeLayout>
- <!-- 中间三个button 我的跟帖,我的收藏,消息推送 -->
- <LinearLayout
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal">
- <Button
- android:id="@+id/right_permsg_center_btn_thread"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="我的跟帖"
- android:drawableTop="@drawable/biz_pc_go_tie"
- android:background="#00000000"
- android:textColor="@color/whilte"
- android:layout_weight="1"
- />
- <Button
- android:id="@+id/right_permsg_center_btn_collect"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="我的收藏"
- android:drawableTop="@drawable/biz_pc_go_favor"
- android:background="#00000000"
- android:textColor="@color/whilte"
- android:layout_weight="1"
- />
- <Button
- android:id="@+id/right_permsg_center_btn_msgpush"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="消息推送"
- android:drawableTop="@drawable/biz_pc_go_msg"
- android:background="#00000000"
- android:textColor="@color/whilte"
- android:layout_weight="1"
- />
- </LinearLayout>
- </LinearLayout>
主Fragment HomeFragment
[java] view plain cop
- package
- import
- import
- import
- import
- import
- import
- import
- import
- import
- import
- import
- import
- public class HomeFragment extends
- private
- private static final String[] titles = {"One","Two","Three","Four","Five"};
- private List<ContentBean> list = new
- private
- public
- @Override
- public
- Bundle savedInstanceState) {
- false);
- initData();
- findView(rootView);
- return
- }
- private void
- for(int i=0;i<titles.length;i++){
- new
- cb.setTitle(titles[i]);
- "_"+(i+1));
- list.add(cb);
- }
- }
- private void
- mViewPager = (ViewPager) rootView.findViewById(R.id.mViewPager);
- PagerTabStrip mPagerTabStrip = (PagerTabStrip) rootView.findViewById(R.id.mPagerTabStrip);
- mPagerTabStrip.setTabIndicatorColor(getResources().getColor(R.color.select_text_color));
- new
- mViewPager.setAdapter(mAdapter);
- }
- @Override
- public void
- if(mAdapter!=null){
- mAdapter.notifyDataSetChanged();
- }
- super.onStart();
- }
- }
HomeFragment 布局文件 fragment_home.xml
[html] view plain co
- <?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" >
- <android.support.v4.view.ViewPager
- android:id="@+id/mViewPager"
- android:layout_width="match_parent"
- android:layout_height="wrap_content" >
- <android.support.v4.view.PagerTabStrip
- android:id="@+id/mPagerTabStrip"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="top"/>
- <!-- <android.support.v4.view.PagerTitleStrip
- android:id="@+id/mPagerTitleStrip"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_gravity="top" /> -->
- </android.support.v4.view.ViewPager>
- </RelativeLayout>
别的就不贴了,自己下载下来看吧