5

我有一个滑动窗格布局,其中包含一个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>

这是按钮功能的代码

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

        }
    });
4

3 回答 3

11

在您的 CustomSlidingPaneLayout 视图类中编写以下代码,并在您的 xml 文件中使用此自定义布局。它将完美地满足您的要求。

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

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

完整的自定义视图类:

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
}
}
于 2015-09-19T18:13:24.843 回答
0

我没有使用 SDK 中的滑动面板,但这个 com.sothree.slidinguppanel 可以完美运行。这个库没有这个问题。

于 2015-08-22T06:24:10.490 回答
0

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

binding.clMenu.layoutParams.width = 0clMenu声明的第一个布局在哪里SlidingPaneLayout

于 2021-02-26T13:09:09.697 回答