gpt4 book ai didi

android - 为 SlidingPaneLayout 禁用滑动手势

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:52:46 26 4
gpt4 key购买 nike

我有一个包含 ListView 的滑动 Pane 布局。我有一个按钮可以打开滑动 Pane 。因此,我想禁用此滑动 Pane 的滑动手势,这在我尝试访问同一布局中的任何其他 View 时会产生问题。

有没有办法只禁用滑动手势并让按钮功能正常工作?它应该像往常一样在单击按钮时打开和关闭滑动 Pane 。

下面是我的 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();
}

}
});

最佳答案

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

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

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

完整的自定义 View 类:

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
}
}

关于android - 为 SlidingPaneLayout 禁用滑动手势,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32152874/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com