androidlistviewslidingpanelayout

ListView inside of SlidingPaneLayout


I have an activity layout like this:

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

Now, on the 'FrameLayout' with id: 'courseActivityContentFragmentContainer' I add a 'Fragment' which contains several 'Fragment's in it, one of them contains a 'ListView' inside its view layout.

The issue is that when I scroll the list, it begins to scroll but then the 'SlidingPaneLayout' takes control and slides the pane layout.

Any thoughts?


Solution

  • The solution I found was extend the 'SlidingPaneLayout' and to pass the visible rectangle of the of the 'ListView' to it so it won't intercept touch events that inside the 'ListView'

    Here's is the code:

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

    By the way, I do a try and catch because sometimes there's a 'NullPointerException' thrown, I couldn't find out why.