5

I have a sliding pane layout which contains a ListView. I have a button to open the sliding pane. So I want to disable the swipe gesture for this sliding pane which is creating a problem when I am trying to access any other view in the same layout.

Is there anyway to only make the swipe gesture disabled and have the button functionality should work? It should open and close the sliding pane as usual on button click.

Below is part of my XML layout:

<android.support.v4.widget.SlidingPaneLayout
    android:id="@+id/sliding_pane_layout_accountHome"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff" >

    <LinearLayout
        android:layout_width="280dp"
        android:layout_height="match_parent"
        android:orientation="vertical" 
        android:background="#FFFFFF">

        <ListView
            android:id="@+id/lv_menuList"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

    </LinearLayout>
</android.support.v4.widget.SlidingPaneLayout>

Here is code for button functionality

slidingLayout1 = (SlidingPaneLayout) findViewById(R.id.sliding_pane_layout_accountHome);
slidingLayout1.openPane();

iv_menu=(ImageView)findViewById(R.id.iv_menu);
    iv_menu.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) 
        {
            if(slidingLayout1.isOpen()==true)
            {
                slidingLayout1.closePane();
            }
            else
            {
                slidingLayout1.openPane();
            }

        }
    });
Jared Rummler
  • 37,824
  • 19
  • 133
  • 148

4 Answers4

11

write below code in your CustomSlidingPaneLayout view class, And use this custom layout in your xml file. It will work perfectly with your requirement.

@Override
  public boolean onInterceptTouchEvent(MotionEvent ev) {
   return false;
}

@Override
public boolean onTouchEvent(MotionEvent ev) {
    return false;
}

Full Custom View Class:

public class MySlidingPanelLayout extends SlidingPaneLayout {
// ===========================================================
// Constructors
// ===========================================================
public MySlidingPanelLayout(Context context) {
    super(context);
    // TODO Auto-generated constructor stub
}

public MySlidingPanelLayout(Context context, AttributeSet attrs,
        int defStyle) {
    super(context, attrs, defStyle);
    // TODO Auto-generated constructor stub
}

public MySlidingPanelLayout(Context context, AttributeSet attrs) {
    super(context, attrs);
    // TODO Auto-generated constructor stub
}

// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    return false;
}

@Override
public boolean onTouchEvent(MotionEvent event) {
    MyLog.i("MySlidingPanelLayout", "onTouch:");
    if (this.isOpen()) {
        this.closePane();
    }
    return false; // here it returns false so that another event's listener
                    // should be called, in your case the MapFragment
                    // listener
}
}
Asad Rao
  • 3,190
  • 1
  • 22
  • 26
  • 1
    If **onInterceptTouchEvent()** returns false, **onTouchEvent()** won't be called. Thus overriding **onTouchEvent()**, does not have any effect and not needed. **https://developer.android.com/training/gestures/viewgroup.html** – Arash Aug 04 '17 at 11:31
0

I'm not using slidingpanel from SDK but this one com.sothree.slidinguppanel which works perfectly. You don't have this problem with this library.

fab
  • 790
  • 6
  • 10
0

I know this thread is pretty old but in case anyone wants to how to go around this without overriding nothing, you just want to set the width of the layout menu's layoutParams to zero.

binding.clMenu.layoutParams.width = 0 where clMenu is the first layout declared within SlidingPaneLayout.

Jim Ovejera
  • 739
  • 6
  • 10
0

According to https://developer.android.com/develop/ui/views/layout/twopane, you can use:

slidingPaneLayout.lockMode = SlidingPaneLayout.LOCK_MODE_LOCKED