drawerLayout-滑动侧边栏

1.首先我们看一下它的监听事件的生命周期

代码如下

 mDrawerLayout.setDrawerListener(new DrawerListener() {
            @Override
            public void onDrawerStateChanged(int arg0) {
                mHistoryHideButton.startAnimation(myAnimation);
                android.util.Log.e("zhangshuli", "statechange");
            }   

            @Override
            public void onDrawerSlide(View arg0, float arg1) {
                mHistoryHideButton.startAnimation(myAnimationRecover);
                android.util.Log.e("zhangshuli", "slide");

            }   

            @Override
            public void onDrawerOpened(View arg0) {
                myHistoryAnimationSetCount = 0;
                myHistoryItemCount= mHistory.mEntries.size()-1;
                if (mHistoryDisplayList.getCount() == 0) {
                    mHistoryClearButton.setEnabled(false);
                } else {
                    mHistoryClearButton.setEnabled(true);
                }
                android.util.Log.e("zhangshuli", "open");
            }   

            @Override
            public void onDrawerClosed(View arg0) {
                history_clear_choose.setVisibility(View.GONE);
                android.util.Log.e("zhangshuli", "colse");
            }
        });

当我们直接点开,也就是执行

if (!mDrawerLayout.isDrawerVisible(GravityCompat.END)) {
                    mDrawerLayout.openDrawer(GravityCompat.END);
                }  

的时候,打印结果如下

03-21 11:58:57.163 E/zhangshuli(28603): statechange
03-21 11:58:57.171 E/zhangshuli(28603): slide
03-21 11:58:57.204 E/zhangshuli(28603): slide
03-21 11:58:57.238 E/zhangshuli(28603): slide
03-21 11:58:57.262 E/zhangshuli(28603): slide
03-21 11:58:57.290 E/zhangshuli(28603): slide
03-21 11:58:57.317 E/zhangshuli(28603): slide
03-21 11:58:57.341 E/zhangshuli(28603): slide
03-21 11:58:57.366 E/zhangshuli(28603): slide
03-21 11:58:57.393 E/zhangshuli(28603): slide
03-21 11:58:57.420 E/zhangshuli(28603): slide
03-21 11:58:57.445 E/zhangshuli(28603): slide
03-21 11:58:57.470 E/zhangshuli(28603): slide
03-21 11:58:57.496 E/zhangshuli(28603): slide
03-21 11:58:57.519 E/zhangshuli(28603): slide
03-21 11:58:57.545 E/zhangshuli(28603): slide
03-21 11:58:57.590 E/zhangshuli(28603): open
03-21 11:58:57.591 E/zhangshuli(28603): statechange

我们可以看到

onDrawerStateChanged 在状态开始改变跟状态改变完成以后各执行一次
onDrawerOpened 最终打开以后执行
onDrawerSlide 一直在移动的过程中执行

关闭的时候,点击关闭

03-21 12:05:27.180 E/zhangshuli(28603): statechange
03-21 12:05:27.190 E/zhangshuli(28603): slide
03-21 12:05:27.215 E/zhangshuli(28603): slide
03-21 12:05:27.246 E/zhangshuli(28603): slide
03-21 12:05:27.270 E/zhangshuli(28603): slide
03-21 12:05:27.295 E/zhangshuli(28603): slide
03-21 12:05:27.319 E/zhangshuli(28603): slide
03-21 12:05:27.349 E/zhangshuli(28603): slide
03-21 12:05:27.378 E/zhangshuli(28603): slide
03-21 12:05:27.412 E/zhangshuli(28603): slide
03-21 12:05:27.440 E/zhangshuli(28603): slide
03-21 12:05:27.463 E/zhangshuli(28603): slide
03-21 12:05:27.485 E/zhangshuli(28603): slide
03-21 12:05:27.506 E/zhangshuli(28603): slide
03-21 12:05:27.527 E/zhangshuli(28603): slide
03-21 12:05:27.561 E/zhangshuli(28603): slide
03-21 12:05:27.601 E/zhangshuli(28603): colse
03-21 12:05:27.601 E/zhangshuli(28603): statechange

跟上面唯一的区别也就是

彻底关闭的时候,执行

onDrawerClosed

当我们是滑动打开的时候

03-21 12:09:20.367 E/zhangshuli(28603): statechange
03-21 12:09:20.375 E/zhangshuli(28603): slide
03-21 12:09:20.395 E/zhangshuli(28603): statechange
03-21 12:09:20.439 E/zhangshuli(28603): slide
03-21 12:09:20.470 E/zhangshuli(28603): slide
03-21 12:09:20.500 E/zhangshuli(28603): slide
03-21 12:09:20.524 E/zhangshuli(28603): slide
03-21 12:09:20.548 E/zhangshuli(28603): slide
03-21 12:09:20.572 E/zhangshuli(28603): slide
03-21 12:09:20.599 E/zhangshuli(28603): slide
03-21 12:09:20.621 E/zhangshuli(28603): slide
03-21 12:09:20.643 E/zhangshuli(28603): slide
03-21 12:09:20.666 E/zhangshuli(28603): slide
03-21 12:09:20.689 E/zhangshuli(28603): slide
03-21 12:09:20.713 E/zhangshuli(28603): slide
03-21 12:09:20.736 E/zhangshuli(28603): slide
03-21 12:09:20.760 E/zhangshuli(28603): slide
03-21 12:09:20.785 E/zhangshuli(28603): slide
03-21 12:09:20.810 E/zhangshuli(28603): slide
03-21 12:09:20.834 E/zhangshuli(28603): slide
03-21 12:09:20.859 E/zhangshuli(28603): slide
03-21 12:09:20.882 E/zhangshuli(28603): slide
03-21 12:09:20.906 E/zhangshuli(28603): slide
03-21 12:09:20.931 E/zhangshuli(28603): slide
03-21 12:09:20.962 E/zhangshuli(28603): slide
03-21 12:09:20.994 E/zhangshuli(28603): slide
03-21 12:09:21.019 E/zhangshuli(28603): slide
03-21 12:09:21.045 E/zhangshuli(28603): slide
03-21 12:09:21.070 E/zhangshuli(28603): slide
03-21 12:09:21.094 E/zhangshuli(28603): slide
03-21 12:09:21.118 E/zhangshuli(28603): slide
03-21 12:09:21.143 E/zhangshuli(28603): slide
03-21 12:09:21.168 E/zhangshuli(28603): slide
03-21 12:09:21.193 E/zhangshuli(28603): slide
03-21 12:09:21.218 E/zhangshuli(28603): slide
03-21 12:09:21.241 E/zhangshuli(28603): slide
03-21 12:09:21.266 E/zhangshuli(28603): slide
03-21 12:09:21.291 E/zhangshuli(28603): slide
03-21 12:09:21.318 E/zhangshuli(28603): slide
03-21 12:09:21.343 E/zhangshuli(28603): slide
03-21 12:09:21.367 E/zhangshuli(28603): slide
03-21 12:09:21.392 E/zhangshuli(28603): slide
03-21 12:09:21.417 E/zhangshuli(28603): slide
03-21 12:09:21.442 E/zhangshuli(28603): slide
03-21 12:09:21.469 E/zhangshuli(28603): slide
03-21 12:09:21.494 E/zhangshuli(28603): slide
03-21 12:09:21.519 E/zhangshuli(28603): slide
03-21 12:09:21.544 E/zhangshuli(28603): slide
03-21 12:09:21.569 E/zhangshuli(28603): slide
03-21 12:09:21.597 E/zhangshuli(28603): slide
03-21 12:09:21.623 E/zhangshuli(28603): slide
03-21 12:09:21.649 E/zhangshuli(28603): slide
03-21 12:09:21.674 E/zhangshuli(28603): slide
03-21 12:09:21.698 E/zhangshuli(28603): slide
03-21 12:09:21.724 E/zhangshuli(28603): slide
03-21 12:09:21.750 E/zhangshuli(28603): slide
03-21 12:09:21.776 E/zhangshuli(28603): slide
03-21 12:09:21.801 E/zhangshuli(28603): slide
03-21 12:09:21.832 E/zhangshuli(28603): slide
03-21 12:09:21.858 E/zhangshuli(28603): slide
03-21 12:09:21.882 E/zhangshuli(28603): slide
03-21 12:09:21.906 E/zhangshuli(28603): slide
03-21 12:09:21.930 E/zhangshuli(28603): slide
03-21 12:09:21.955 E/zhangshuli(28603): slide
03-21 12:09:21.980 E/zhangshuli(28603): slide
03-21 12:09:22.007 E/zhangshuli(28603): slide
03-21 12:09:22.035 E/zhangshuli(28603): slide
03-21 12:09:22.062 E/zhangshuli(28603): slide
03-21 12:09:22.262 E/zhangshuli(28603): open
03-21 12:09:22.262 E/zhangshuli(28603): statechange

其实跟我们直接点开没太大区别,就是

onDrawerSlide 一直在执行。所以,这个方法应该可以得到你的移动坐标

滑动关闭的时候

03-21 12:11:38.056 E/zhangshuli(28603): statechange
03-21 12:11:38.073 E/zhangshuli(28603): slide
03-21 12:11:38.100 E/zhangshuli(28603): slide
03-21 12:11:38.130 E/zhangshuli(28603): slide
03-21 12:11:38.161 E/zhangshuli(28603): slide
03-21 12:11:38.193 E/zhangshuli(28603): slide
03-21 12:11:38.222 E/zhangshuli(28603): slide
03-21 12:11:38.250 E/zhangshuli(28603): slide
03-21 12:11:38.275 E/zhangshuli(28603): slide
03-21 12:11:38.298 E/zhangshuli(28603): slide
03-21 12:11:38.322 E/zhangshuli(28603): slide
03-21 12:11:38.347 E/zhangshuli(28603): slide
03-21 12:11:38.371 E/zhangshuli(28603): slide
03-21 12:11:38.402 E/zhangshuli(28603): slide
03-21 12:11:38.429 E/zhangshuli(28603): slide
03-21 12:11:38.457 E/zhangshuli(28603): slide
03-21 12:11:38.483 E/zhangshuli(28603): slide
03-21 12:11:38.508 E/zhangshuli(28603): slide
03-21 12:11:38.534 E/zhangshuli(28603): slide
03-21 12:11:38.559 E/zhangshuli(28603): slide
03-21 12:11:38.582 E/zhangshuli(28603): slide
03-21 12:11:38.606 E/zhangshuli(28603): slide
03-21 12:11:38.631 E/zhangshuli(28603): slide
03-21 12:11:38.657 E/zhangshuli(28603): slide
03-21 12:11:38.688 E/zhangshuli(28603): slide
03-21 12:11:38.714 E/zhangshuli(28603): slide
03-21 12:11:38.741 E/zhangshuli(28603): slide
03-21 12:11:38.767 E/zhangshuli(28603): slide
03-21 12:11:38.796 E/zhangshuli(28603): slide
03-21 12:11:38.823 E/zhangshuli(28603): slide
03-21 12:11:38.849 E/zhangshuli(28603): slide
03-21 12:11:38.876 E/zhangshuli(28603): slide
03-21 12:11:38.903 E/zhangshuli(28603): slide
03-21 12:11:38.930 E/zhangshuli(28603): slide
03-21 12:11:38.959 E/zhangshuli(28603): slide
03-21 12:11:38.986 E/zhangshuli(28603): slide
03-21 12:11:39.009 E/zhangshuli(28603): slide
03-21 12:11:39.032 E/zhangshuli(28603): slide
03-21 12:11:39.066 E/zhangshuli(28603): slide
03-21 12:11:39.135 E/zhangshuli(28603): slide
03-21 12:11:39.160 E/zhangshuli(28603): slide
03-21 12:11:39.184 E/zhangshuli(28603): slide
03-21 12:11:39.212 E/zhangshuli(28603): slide
03-21 12:11:39.239 E/zhangshuli(28603): slide
03-21 12:11:39.349 E/zhangshuli(28603): statechange
03-21 12:11:39.360 E/zhangshuli(28603): slide
03-21 12:11:39.383 E/zhangshuli(28603): slide
03-21 12:11:39.404 E/zhangshuli(28603): slide
03-21 12:11:39.425 E/zhangshuli(28603): slide
03-21 12:11:39.446 E/zhangshuli(28603): slide
03-21 12:11:39.467 E/zhangshuli(28603): slide
03-21 12:11:39.488 E/zhangshuli(28603): slide
03-21 12:11:39.508 E/zhangshuli(28603): slide
03-21 12:11:39.529 E/zhangshuli(28603): slide
03-21 12:11:39.549 E/zhangshuli(28603): slide
03-21 12:11:39.585 E/zhangshuli(28603): slide
03-21 12:11:39.619 E/zhangshuli(28603): colse
03-21 12:11:39.619 E/zhangshuli(28603): statechange

也是一样的。所以,在它的方法中,我们可以做很多事情

				
时间: 2024-09-30 21:09:29

drawerLayout-滑动侧边栏的相关文章

js实现上下滑动侧边栏

给一个原先的电子商务网站做修改,客户说想将原先上下滑动侧边栏改的更加人性化,希望将原先匀速滑动的侧边栏改成变速运动的侧边栏,在到达目的地之前速度越变越慢. 原先一开始的时候,,这个图片是硬生生地到达可视区的中点,看得有点愣愣傻傻的. 原先的代码是这样: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transit

基于Bootstrup的jQuery滑动侧边栏插件

Bootstrap Offcanvas是一款非常简单的jQuery隐藏滑动侧边栏插件.该jQuery插件使用Bootstrup的样式和标签来创建隐藏的滑动侧边栏,在大屏幕上会显示正常的导航菜单,当屏幕尺寸缩小到一定尺寸时该滑动侧边栏才会出现. 在线演示:http://www.htmleaf.com/Demo/201502281433.html 下载地址:http://www.htmleaf.com/jQuery/Menu-Navigation/201502281432.html

Android开发--滑动侧边栏的实现

在Android应用开发中,滑动侧边栏经常使用,今天我也试着自己进行了一个简单的实践,虽然功能还不是很强大,但是可以保留下来为以后的开发使用,有需要时在进行简单的修改.实现一个滑动侧边栏思路也很简单: 1.重写一个SlidingMenu类继承ViewGroup,病危该ViewGroup添加两个子布局,分别为菜单和主界面显示: 2.为了得到一个滑动的效果,选择Scroller帮助我们实现,配合ViewGroup下的computeScroll方法实现界面的更新: 3.利用一个boolean来记录菜单

android学习笔记:DrawerLayout实现侧边栏

DrawerLayout需要的布局文件 首先要以 android.support.v4.widget.DrawerLayout 作为标签. 另外需要将设置的侧边栏布局的 android:layout_gravity="start" start设置为左边布局,end设置为右边布局. 在activity中的代码: private DrawerLayout mDrawerLayout; private ActionBarDrawerToggle mActionBarDrawerToggle;

android 滑动侧边栏 SlideMenu 源码分析 以及使用手册

我们先看使用方案: 首先 public class MainActivity extends SlidingFragmentActivity 继承SlidingFragmentActivity ,这里面在创建时有创建需要的slidemenu等相关数据. 在Oncreate里面添加 private void init_sm() { sm = getSlidingMenu();   // 获取menu sm.setMode(SlidingMenu.LEFT_RIGHT);// 设置为左右都有 sm.

android自带DrawerLayout滑动菜单的使用

受到slidingMenu的启发android增加了DrawerLayout来实现滑动菜单 DrawerLayout是继承自ViewGroup,可以在其中放子view.DrawerLayout中分为主内容区和菜单区域 使用方法如下 1.和普通的LinearLayout一样 <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" androi

带滑动侧边栏的联系人界面

先上效果图,呵呵,首先说明这个效果本人还是比较满意的~ 首先来分析一下页面元素的,其实就是左侧的一个listview和右侧的一个自定义linearlayout,右侧部分进行滑动时,左侧的联系人可以随着字母进行移动. 这个效果用到的知识还是挺多的.然而“青青翠竹无非般若,郁郁黄花皆是妙谛”,认清了事务的内在规律都是不难,接着允许本人讲一下~ 1.普及知识,汉字转gb2312码和byte型数据 gb2312中的英文字符是与ascii码一致的,一个字节.汉字字符是两个字节,分为高八位和低八位:高字节的

CSS3超酷移动手机滑动隐藏侧边栏菜单特效

这是一组共4种效果非常炫酷的CSS3移动手机滑动隐藏侧边栏菜单特效.这四种效果分别是:默认的点击滑动侧边栏菜单效果.带3D transforms的滑动侧边栏效果.文字缩放和淡入淡出效果的滑动侧边栏以及使用translate来实现滑动侧边栏的效果. 每一个滑动侧边栏效果都带有从右到左淡入淡出的滑动过渡效果.菜单栏中的菜单项以一个接一个的方式显示,这种效果是通过为它们分别添加 transition-delay 来实现的.下面来看看默认的滑动侧边栏效果的制作方法. 插件中使用了font-awesome

微信小程序侧边栏滑动特效(左右滑动)

侧边栏滑动是很常见的功能,但是小程序出来不久,很多特效还没有成熟案例,只能原生重写,所以今天为大家带来4个漂亮的侧边栏特效~~ 侧边栏特效一 先看效果: wxml: <!--page/one/index.wxml--> <view class="page"> <view class="page-bottom"> <view class="page-content"> <view class=&

slidingMenu有时候需要关闭侧边栏

12个页签能往左滑动 但是往右滑动侧边栏就出来了 我们ViewPager的事件被占用了,那么就得关闭侧边栏的事件(第一个页签可以开启) 那么写个方法关闭侧边栏 slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);或者 SlidingMenu.TOUCHMODE_NONE 参数来禁用就可以了 传入true可以滑动呼出侧边栏 false禁止,这样只要判断页签的position 传入true或者false就可以了 privat