SlidingPaneLayout中的ListView

时间:2015-01-26 17:04:47

标签: android listview slidingpanelayout

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

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

现在,在&#39; FrameLayout&#39; id:&#39; courseActivityContentFragmentContainer&#39;我添加了一个片段&#39;其中包含几个片段,其中一个包含一个&#39; ListView&#39;在其视图布局中。

问题在于,当我滚动列表时,它会开始滚动,然后是&#39; SlidingPaneLayout&#39;控制并滑动窗格布局。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

我找到的解决方案是扩展&#39; SlidingPaneLayout&#39;并传递&#39; ListView&#39;的可见矩形。因此它不会拦截“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”#39;抛出,我无法找到原因。