禁用SlidingPaneLayout的滑动手势

Sai*_*ana 4 android swipe-gesture slidingpanelayout

我有一个滑动窗格布局,其中包含一个ListView.我有一个按钮来打开滑动窗格.因此,我想禁用此滑动窗格的滑动手势,当我尝试访问同一布局中的任何其他视图时,这会产生问题.

反正只有禁用滑动手势并且按钮功能应该有效吗?它应该像往常一样在按钮点击时打开和关闭滑动窗格.

以下是我的XML布局的一部分:

<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>
Run Code Online (Sandbox Code Playgroud)

这是按钮功能的代码

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

        }
    });
Run Code Online (Sandbox Code Playgroud)

Asa*_*Rao 10

在CustomSlidingPaneLayout视图类中编写以下代码,并在xml文件中使用此自定义布局.它将完全符合您的要求.

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

@Override
public boolean onTouchEvent(MotionEvent ev) {
    return false;
}
Run Code Online (Sandbox Code Playgroud)

完全自定义视图类:

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
}
}
Run Code Online (Sandbox Code Playgroud)