2015-04-27 31 views
0

导航抽屉抽屉式导航自定义触控动作有3种行为android系统中创建的Android

- Always opened, and can be close only programming using LOCK_MODE_LOCKED_OPEN. 
    - Always closed, and can be open only programming LOCK_MODE_LOCKED_CLOSED. 
    - User can open and close the drawer. using LOCK_MODE_UNLOCKED 

第三个,如果用户点击了侧的抽屉打开时会自动关闭。而第一个将永远保持开放。

I need to have custom one that user can open and close the drawer, and when he clicks outside the drawer it will remains open. 

我想重写onInterceptTouchEvent。

任何一个人做了一些similer?

/*********交锋*********** 我延长了DrawerLayout,和它的作品还没有确定,如果100%

public class CustomDrawerLayout extends DrawerLayout { 
    Context ccontext; 
    public CustomDrawerLayout(Context context) { 
     this(context, null); 
    } 

public CustomDrawerLayout(Context context, AttributeSet attrs) { 
    this(context, attrs, 0); 
} 

public CustomDrawerLayout(Context context, AttributeSet attrs, int defStyle)  { 
super(context,attrs,defStyle); 
    this.ccontext = context; 
} 

//@Override 
public boolean onTouchEvent(MotionEvent ev) { 
    final int action = ev.getAction(); 


    switch (action & MotionEventCompat.ACTION_MASK) { 


     case MotionEvent.ACTION_UP: { 
      final float x = ev.getX(); 
      final float y = ev.getY(); 
      boolean peekingOnly = true; 
      final View touchedView = findTopChildUnder((int) x, (int) y); 
      if (touchedView != null && touchedView instanceof FrameLayout) { 
       return true; 
      } 
      break; 
     } 
    } 
    return super.onTouchEvent(ev); 

} 

public View findTopChildUnder(int x, int y) { 
    final int childCount = this.getChildCount(); 
    for (int i = childCount - 1; i >= 0; i--) { 
     final View child = this.getChildAt(i); 
     if (x >= child.getLeft() && x < child.getRight() && 
       y >= child.getTop() && y < child.getBottom()) { 
      return child; 
     } 
    } 
    return null; 
} 
} 

回答

0

正是如此你知道,这样做违反了Android指南。

https://developer.android.com/design/patterns/navigation-drawer.html

当导航抽屉被扩展,用户可以通过四种方式驳回:在屏幕任意位置之外触摸内容导航抽屉滑动到左侧(包括从右侧滑动)触摸操作栏中的应用程序图标/标题

+0

我知道,但这是我的应用程序需要 –

+0

AFAIK这并不支持它 – VVB

+0

,但它现在适用于我 –