简介

易信是一个操作比较简介的界面。类似的SlidingMenu还有百度影音、快播等等。下面就是一个模仿易信的一个界面,先看一下效果图

项目源代码下载:https://github.com/nuptboyzhb/SlidingMenuDemoYiXin

或者直接git : $ git clone https://github.com/nuptboyzhb/SlidingMenuDemoYiXin.git


Android仿易信界面SlidingMenu左右滑动_SlidingMenu

首页


Android仿易信界面SlidingMenu左右滑动_ide_02

左边滑动效果


Android仿易信界面SlidingMenu左右滑动_github_03

右边滑动效果

主要代码:


[java]  
   view plain 
   copy 
    
    
    
   
 
 
1. package edu.njupt.zhb.slidemenu;  
2. import edu.njupt.zhb.slidemenu.R;  
3.   
4. import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;  
5. import com.jeremyfeinstein.slidingmenu.lib.app.SlidingFragmentActivity;  
6. import android.os.Bundle;  
7. import android.support.v4.app.Fragment;  
8. import android.support.v4.app.FragmentTransaction;  
9. import android.view.View;  
10. import android.view.View.OnClickListener;  
11. import android.widget.ImageButton;  
12.   
13.   
14. public class MainActivity extends SlidingFragmentActivity implements OnClickListener{  
15. protected SlidingMenu leftRightSlidingMenu;  
16. private ImageButton ivTitleBtnLeft;  
17. private ImageButton ivTitleBtnRight;  
18. private Fragment mContent;  
19. @Override  
20. public void onCreate(Bundle savedInstanceState) {  
21. super.onCreate(savedInstanceState);  
22.         initLeftRightSlidingMenu();  
23.         setContentView(R.layout.activity_main);  
24.         initView();  
25.     }  
26.       
27.       
28. private void initView() {  
29. this.findViewById(R.id.ivTitleBtnLeft);  
30. this);  
31. this.findViewById(R.id.ivTitleBtnRight);  
32. this);  
33.     }  
34.   
35. private void initLeftRightSlidingMenu() {  
36. new FragmentDefaultMain();  
37.         getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, mContent).commit();  
38.         setBehindContentView(R.layout.main_left_layout);  
39.         FragmentTransaction leftFragementTransaction = getSupportFragmentManager().beginTransaction();  
40. new LeftSlidingMenuFragment();  
41.         leftFragementTransaction.replace(R.id.main_left_fragment, leftFrag);  
42.         leftFragementTransaction.commit();  
43. // customize the SlidingMenu  
44.         leftRightSlidingMenu = getSlidingMenu();  
45. // 设置是左滑还是右滑,还是左右都可以滑,我这里只做了左滑  
46. // 设置菜单宽度  
47. 0.35f);// 设置淡入淡出的比例  
48. //设置手势模式  
49. // 设置左菜单阴影图片  
50. true);// 设置滑动时菜单的是否淡入淡出  
51. 0.333f);// 设置滑动时拖拽效果  
52.           
53.         leftRightSlidingMenu.setSecondaryMenu(R.layout.main_right_layout);  
54.         FragmentTransaction rightFragementTransaction = getSupportFragmentManager().beginTransaction();  
55. new RightSlidingMenuFragment();  
56.         leftFragementTransaction.replace(R.id.main_right_fragment, rightFrag);  
57.         rightFragementTransaction.commit();  
58.     }  
59.       
60. @Override  
61. public void onClick(View v) {  
62. switch (v.getId()) {  
63. case R.id.ivTitleBtnLeft:  
64.             leftRightSlidingMenu.showMenu();  
65. break;  
66. case R.id.ivTitleBtnRight:  
67. true);  
68. break;  
69. default:  
70. break;  
71.         }  
72.           
73.     }  
74.    
75.   
76. /**
77.      *    左侧菜单点击切换首页的内容
78.      */  
79.       
80. public void switchContent(Fragment fragment) {  
81.         mContent = fragment;  
82.         getSupportFragmentManager()  
83.         .beginTransaction()  
84.         .replace(R.id.content_frame, fragment)  
85.         .commit();  
86.         getSlidingMenu().showContent();  
87.     }  
88.       
89.       
90. }






Android仿易信界面SlidingMenu左右滑动_ide_04


代码结构


源代码下载:https://github.com/nuptboyzhb/SlidingMenuDemoYiXin