您的位置:首页 > 其它

SlidingMenu侧滑简单实现

2017-04-16 18:28 162 查看
建立一个空的xml布局文件,布局里用FrameLayout给FrameLayout一个ID  id是(红色字体部分)添加空的布局是黄色字体部分

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/menu_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />

在建立一个xml布局,内写入你想要侧滑内的布局

在建立一个类继承Fragment 在下面方法中实例化一个对象(蓝色字体部分)


写在方法内方法名自拟

setBehindContentView(R.layout.menu_frame_left);
MenuLeftFragment menuLeftFragment = new MenuLeftFragment();
int commit = getSupportFragmentManager().beginTransaction()
.replace(R.id.menu_frame, menuLeftFragment).commit();
int mWidthPixels = this.getResources().getDisplayMetrics().widthPixels;
// 实例化滑动菜单对象
mMenu = getSlidingMenu();
// 设置可以左右滑动的菜单
mMenu.setMode(SlidingMenu.LEFT);
// 设置滑动菜单视图的宽度
mMenu.setBehindWidth(mWidthPixels /4*3);
// 设置渐入渐出效果的值
mMenu.setFadeDegree(0.35f);
// 设置触摸屏幕的模式,这里设置为全屏
mMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
// 设置下方视图的在滚动时的缩放比例
mMenu.setBehindScrollScale(0.0f);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐