SlindingMenu 侧滑菜单框架使用
来源:互联网 发布:淘宝网商贷款扣钱 编辑:程序博客网 时间:2024/06/03 21:38
SlindingMenu 侧滑菜单框架使用
下载并引入开源框架
一、 SlindingMenu 是github上侧滑菜单框架的开源项目。可以轻松的开发出安卓左侧策划菜单、右侧策划菜单和左右双侧侧滑菜单。
二、SlidingMenu开源项目的下载在浏览器中输入:https://github.com/jfeinstein10/SlidingMenu,在页面的右下角的[Download ZIP]下载。现在完成后解压,将[SlidingMenu-master]目录下的library项目导入到项目中。
三、在开发工具中右击工程名,选择[Properties]-->Android选项卡,右下角单击[Add]将刚才导入的库作为库导入。
四、如果产生了错误,一定是因为引入的库文件与项目都包含一个jar文件[*\libs\android-support-v4.jar],当时他们两个文件对应的SHA1签名不一致导致,可以覆盖或删除项目中的该jar文件。
五、以上都无误后,将需要引入的侧滑菜单的Activity修改成继承[SlidingFragmentActivity],如果继承后运行正常则证明开源项目作为Libraries引入成功
侧滑菜单的开发和使用
一、左侧菜单布局文件的代码
<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/leftmenu" android:layout_width="match_parent" android:layout_height="match_parent" ></FrameLayout>
二、内容显示布局文件的代码
<?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" ></FrameLayout>
<RelativeLayout 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" tools:context=".MainActivity" > <include layout="@layout/content" /> </RelativeLayout>
三、左侧Fragment的代码
package com.example.newsdemo.fragment;import java.util.ArrayList;import java.util.List;import com.example.newsdemo.MainActivity;import com.example.newsdemo.R;import android.os.Bundle;import android.support.v4.app.Fragment;import android.support.v4.app.FragmentActivity;import android.util.Log;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.AdapterView;import android.widget.AdapterView.OnItemClickListener;import android.widget.ArrayAdapter;import android.widget.ListView;public class MenuFragment extends Fragment implements OnItemClickListener {private static final String TAG = "MenuFragment";private View view;private ListView listView;private Fragment fragment;private List<Fragment> fragments;@Overridepublic void onCreate(Bundle savedInstanceState) {Log.i(TAG, "onCreate");initFragment();super.onCreate(savedInstanceState);}@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {view = LayoutInflater.from(getActivity()).inflate(R.layout.menu_list_view, null);return view;}@Overridepublic void onActivityCreated(Bundle savedInstanceState) {super.onActivityCreated(savedInstanceState);listView = (ListView) view.findViewById(R.id.lv_menu);listView.setAdapter(new ArrayAdapter(getActivity(),android.R.layout.simple_list_item_1, android.R.id.text1,initData()));listView.setOnItemClickListener(this);}private void initFragment() {// TODO Auto-generated method stubfragments = new ArrayList<Fragment>();fragments.add(new ContentFragment1());fragments.add(new ContentFragment2());fragments.add(new ContentFragment3());fragments.add(new ContentFragment4());fragments.add(new ContentFragment5());fragments.add(new ContentFragment6());}// 初始化listView显示的数据private String[] initData() {String[] strs = new String[6];for (int i = 0; i < strs.length; i++) {strs[i] = "F" + (i + 1);}return strs;}@Overridepublic void onItemClick(AdapterView<?> parent, View view, int position,long id) {if (fragments != null && fragments.size() > position) {fragment = fragments.get(position);switchFragment(fragment);}}public void switchFragment(Fragment fragment) {if (fragment != null && getActivity() instanceof MainActivity) {((MainActivity) getActivity()).switchFragment(fragment);}}}
四、MainActivity的业务逻辑代码
package com.example.newsdemo;import com.example.newsdemo.fragment.MenuFragment;import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;import com.jeremyfeinstein.slidingmenu.lib.app.SlidingFragmentActivity;import android.os.Bundle;import android.support.v4.app.Fragment;import android.support.v4.app.FragmentManager;public class MainActivity extends SlidingFragmentActivity {private FragmentManager manager;private SlidingMenu sm;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setBehindContentView(R.layout.leftmenu);setContentView(R.layout.activity_main);// 得到滑动菜单sm = getSlidingMenu();// 设置菜单显示模式sm.setMode(SlidingMenu.LEFT);// 设置菜单完全显示时占用宽度sm.setBehindWidthRes(R.dimen.slidingmenu_offset);// 设置阴影的Shape动画sm.setShadowDrawable(R.drawable.shadow);// 设置阴影的宽度sm.setShadowWidth(R.dimen.shadow_width);// 设置滑动菜单的touch范围sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);// 右边的滑动菜单/** * 下面的代码是右边侧滑 */// sm.setSecondaryMenu(R.layout.rightmenu);// sm.setSecondaryShadowDrawable(R.drawable.shadowright);// RightMenuFragment rightMenuFragment = new RightMenuFragment();// getSupportFragmentManager().beginTransaction()// .replace(R.id.rightmenu, rightMenuFragment).commit();// ViewPager// 替换leftmenu的界面显示Fragment fragment = new MenuFragment();manager = getSupportFragmentManager();manager.beginTransaction().replace(R.id.leftmenu, fragment, "MenuFragment").commit();}public void switchFragment(Fragment fragment) {// 改变状态sm.toggle();manager.beginTransaction().replace(R.id.content, fragment, "MenuFragment").commit();}}
效果图
0 0
- SlindingMenu 侧滑菜单框架使用
- 高级部分 侧滑菜单框架的使用 SlidingMenu
- android侧滑菜单框架SlidingMenu的使用
- 跨框架菜单menuG5使用
- SJPullDownMenu下拉菜单框架使用
- 侧滑菜单框架 SlidingMenu 属性详解
- 侧滑菜单框架slidingMenu学习总结
- 使用AndroidResideMenu开源框架实现QQ5.0侧滑菜单
- 【框架】侧滑菜单按钮 之SlidingMenu-master框架
- 使用slidingmenu ,侧滑菜单
- 侧滑菜单的使用
- android_菜单的创建_xUtils框架使用
- 侧滑菜单DrawerLayout+Toolbar结合使用,切换菜单
- 最强RecyclerView,Item侧滑菜单,长按拖拽Item,滑动删除Item。可以和任何下拉刷新框架结合使用
- 侧滑菜单的实现方式(二):开源框架
- 使用DrawerLayout实现侧滑菜单
- 怎么使用侧滑菜单SlidingMenu?
- Android SlidingMenu侧滑菜单使用介绍
- hdu 3874 树状数组+离线处理
- Yii 不完全解决方案(二)
- cocos2d-x ios游戏开发初认识(四) 场景的切换
- poj 3096 Surprising Strings
- hdu 1312 Red and Black(DFS)
- SlindingMenu 侧滑菜单框架使用
- STM32 关于GPIO的问题集锦
- leetcode 刷题之路 91 Pascal's Triangle
- how to access virtual machine image
- u-boot-2010.12移植到2440
- HDOJ 4944 FSF’s game
- 博客新开
- atitit. access token是什么??微信平台公众号开发access_token and Web session保持状态机制
- 1408132104-hd-不要62.cpp