2

我有一个这样的活动布局:

<?xml version="1.0" encoding="utf-8"?>
<SlidingPaneLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/course_menu_sliding_layout"
   android:layout_width="match_parent"
   android:background="@color/white"
   android:layout_height="match_parent">

   <!-- Here is any view that will represent your side menu. Don't forget to provide width! -->
   <FrameLayout
       android:id="@+id/course_activity_menu"
       android:layout_width="@dimen/edu5_menu_width"
       android:layout_height="match_parent"
       android:background="@color/white"
       android:layout_gravity="start" />


   <RelativeLayout
       xmlns:android="http://schemas.android.com/apk/res/android"
       android:layout_width="match_parent"
       android:layout_height="match_parent">

       <FrameLayout
           android:id="@+id/courseActivityNavigationController"
           android:layout_width="match_parent"
           android:layout_height="@dimen/edu5_navigation_controller_height"
           />

       <FrameLayout
           android:id="@+id/courseActivityContentFragmentContainer"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:background="@color/c_popup_bg"
           android:layout_below="@id/courseActivityNavigationController"
           />

   </RelativeLayout>
</SlidingPaneLayout>

现在,在 ID 为“courseActivityContentFragmentContainer”的“FrameLayout”上,我添加了一个“Fragment”,其中包含多个“Fragment”,其中一个在其视图布局中包含一个“ListView”。

问题是,当我滚动列表时,它开始滚动,但随后“SlidingPaneLayout”控制并滑动窗格布局。

有什么想法吗?

4

1 回答 1

0

我找到的解决方案是扩展“SlidingPaneLayout”并将“ListView”的可见矩形传递给它,这样它就不会拦截“ListView”内的触摸事件

这是代码:

public class MySlidingPaneLayout extends SlidingPaneLayout {
    private Rect mIgnoreRect;
    ...
    ...
    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        if ( !isOpen() && mIgnoreRect != null && mIgnoreRect.contains((int)ev.getX(), (int)ev.getY()) )
        {
            return false;
        }
        try
        {
            return super.onInterceptTouchEvent(ev);
        }
        catch ( Exception ex )
        {
            Log.e(TAG, "super.onInterceptTouchEvent threw exception", ex);
        }
        return false;
    }
}

顺便说一句,我尝试并抓住,因为有时会抛出“NullPointerException”,我不知道为什么。

于 2015-01-28T09:19:09.517 回答