码迷,mamicode.com
首页 > 其他好文 > 详细

Andirod Studio应用SlidingMenu

时间:2015-04-07 19:41:39      阅读:289      评论:0      收藏:0      [点我收藏+]

标签:andirod studio   slidingmenu   

我的推测控件原理:从我的理解是该自定义控件实例化时候需要接收一个activity,

所以父类中可能写了此activity touch事件,然后再activity的touch事件中来描述

如何呈现slideMenu


1.第一步:下载SlidingMenu

下载地址:https://github.com/jfeinstein10/SlidingMenu

2.第二步:在studio中新建一个项目

3.第三步:导入下载的示例项目的library模块

4.第四步:修改build grade错误并且依赖导入的module

5.新建SlidingMenuHelper


<span style="font-size:14px;">import android.app.Activity;

import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;

/**
 */
public class SlidingMenuHelper {
    Activity mActivity;
    public SlidingMenuHelper(Activity mActivity){
        this.mActivity=mActivity;
    }

    public  SlidingMenu initSlidingMenu() {
        SlidingMenu localSlidingMenu = new SlidingMenu(mActivity);
        localSlidingMenu.setMode(SlidingMenu.LEFT_RIGHT);//设置左右滑菜单
        localSlidingMenu.setTouchModeAbove(SlidingMenu.SLIDING_WINDOW);//设置要使菜单滑动,触碰屏幕的范围,
        //<span style="color:#FF0000;">SLIDING_WINDOW  根据我的实际测试发现此范围在Menu和主内容交接一带,并且在主内容一侧</span>
        //localSlidingMenu.setTouchModeBehind(SlidingMenu.RIGHT);
        localSlidingMenu.setShadowWidthRes(R.dimen.shadow_width);//设置阴影图片的宽度
        localSlidingMenu.setShadowDrawable(R.drawable.shadow);//设置阴影图片
        localSlidingMenu.setBehindOffsetRes(R.dimen.slidingmenu_offset);//设置划出时主页面显示的剩余宽度
        localSlidingMenu.setFadeEnabled(true);//设置滑动时菜单的是否渐变		<span style="white-space:pre">				</span>localSlidingMenu.setFadeDegree(0.35F);//<span style="font-family: Helvetica, arial, freesans, clean, sans-serif;">设置</span>滑动时的渐变程度
        localSlidingMenu.attachToActivity(mActivity, SlidingMenu.RIGHT);//使SlidingMenu附加在Activity右边
//		localSlidingMenu.setBehindWidthRes(R.dimen.left_drawer_avatar_size);//设置SlidingMenu菜单的宽度
        localSlidingMenu.setMenu(R.layout.left_drawer_fragment);//设置menu的布局文件
        localSlidingMenu.setSecondaryMenu(R.layout.right_drawer_fragment);
        localSlidingMenu.setSecondaryShadowDrawable(R.drawable.shadow);
    //    localSlidingMenu.toggle();//动态判断自动关闭或开启SlidingMenu
        localSlidingMenu.setOnOpenedListener(new SlidingMenu.OnOpenedListener() {
            public void onOpened() {

            }
        });
        return localSlidingMenu;
    }
} </span>

6.在MainActivity中应用

public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        SlidingMenuHelper sh =  new SlidingMenuHelper(MainActivity.this);
        sh.initSlidingMenu();
    }

}

DEMO下载http://download.csdn.net/detail/rnzuozuo/8571661

类似文章参考:http://blog.csdn.net/vipzjyno1/article/details/23614675

Andirod Studio应用SlidingMenu

标签:andirod studio   slidingmenu   

原文地址:http://blog.csdn.net/rnzuozuo/article/details/44924515

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!