Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable swipe gesture for SlidingPaneLayout

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();
            }

        }
    });
like image 953
Sai Chakradhar Sana Avatar asked Aug 22 '15 05:08

Sai Chakradhar Sana


1 Answers

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
}
}
like image 119
Asad Rao Avatar answered Sep 28 '22 02:09

Asad Rao