简体   繁体   English

禁用 SlidingPaneLayout 的滑动手势

[英]Disable swipe gesture for SlidingPaneLayout

I have a sliding pane layout which contains a ListView .我有一个包含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:下面是我的 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>

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

        }
    });

write below code in your CustomSlidingPaneLayout view class, And use this custom layout in your xml file.在您的 CustomSlidingPaneLayout 视图类中编写以下代码,并在您的 xml 文件中使用此自定义布局。 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
}
}

I'm not using slidingpanel from SDK but this one com.sothree.slidinguppanel which works perfectly.我没有使用 SDK 中的滑动面板,但是这个 com.sothree.slidinguppanel 可以完美运行。 You don't have this problem with this library.这个库没有这个问题。

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.我知道这个线程已经很老了,但是如果有人想在不覆盖任何内容的情况下解决这个问题,您只需要将布局菜单的layoutParams的宽度设置为零。

binding.clMenu.layoutParams.width = 0 where clMenu is the first layout declared within SlidingPaneLayout . clMenu binding.clMenu.layoutParams.width = 0其中clMenu是在SlidingPaneLayout声明的第一个布局。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM