Question

I have a AndroidSlidingUpPanel with list view as a child. my problem is when the pane is expanded and I try to scroll the ListView, the pane is scrolled instead. I figure out that I have to override the onInterceptTouchEvent and to set specific areas to MotionEvent.ACTION_DOWN (or something like that), but I really lost in this.

Can you please help me and tell me how can I solve this problem, my code is:

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

<com.sothree.slidinguppanel.SlidingUpPanelLayout
    xmlns:sothree="http://schemas.android.com/apk/res-auto"
    android:id="@+id/sliding_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    sothree:collapsedHeight="40dp"
    sothree:dragView="@+id/name"
    sothree:shadowHeight="1dp" >

    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >



    </FrameLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#eee"
        android:clickable="true"
        android:focusable="false" >

        <TextView
            android:id="@+id/name"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_centerHorizontal="true"
            android:text=""
            android:textSize="14sp" />

        <ListView
            android:id="@+id/lv_menu"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingTop="40dp" />
    </RelativeLayout>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>

And the MainActivity:

public class MainActivity extends Activity implements PanelSlideListener, OnItemClickListener {
public static final String SAVED_STATE_ACTION_BAR_HIDDEN = "saved_state_action_bar_hidden";

private ListView _menuListView;
private SlidingUpPanelLayout _slideUpPane;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
    setContentView(R.layout.activity_main);

    _slideUpPane = (SlidingUpPanelLayout) findViewById(R.id.sliding_layout);

    _slideUpPane.setShadowDrawable(getResources().getDrawable(R.drawable.above_shadow));
    _slideUpPane.setAnchorPoint(0.2f);
    _slideUpPane.setPanelSlideListener(this);

    ArrayList<MenuItem> menuItems = new ArrayList<MenuItem>();
    menuItems.add(new MenuItem("Menu Item"));
    menuItems.add(new MenuItem("Menu Item"));
    menuItems.add(new MenuItem("Menu Item"));
    menuItems.add(new MenuItem("Menu Item"));
    menuItems.add(new MenuItem("Menu Item"));
    menuItems.add(new MenuItem("Menu Item"));
    menuItems.add(new MenuItem("Menu Item"));
    menuItems.add(new MenuItem("Menu Item"));
    menuItems.add(new MenuItem("Menu Item"));
    menuItems.add(new MenuItem("Menu Item"));
    menuItems.add(new MenuItem("Menu Item"));
    menuItems.add(new MenuItem("Menu Item"));
    menuItems.add(new MenuItem("Menu Item"));

    _menuListView = (ListView) findViewById(R.id.lv_menu);
    _menuListView.setAdapter(new MenuAdapter(this, menuItems));
    _menuListView.setOnItemClickListener(this);


    boolean actionBarHidden = savedInstanceState != null ?
            savedInstanceState.getBoolean(SAVED_STATE_ACTION_BAR_HIDDEN, false): false;
    if (actionBarHidden) {
        getActionBar().hide();
    }
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public void onPanelSlide(View panel, float slideOffset) {
    Log.i(TAG, "onPanelSlide, offset " + slideOffset);
    if (slideOffset < 0.2) {
        if (getActionBar().isShowing()) {
            getActionBar().hide();
        }
    } else {
        if (!getActionBar().isShowing()) {
            getActionBar().show();
        }
    }

}

@Override
public void onPanelCollapsed(View panel) {
    Log.i(TAG, "onPanelCollaped");
}

@Override
public void onPanelExpanded(View panel) {
    Log.i(TAG, "onPanelExpanded");
}

@Override
public void onPanelAnchored(View panel) {
    Log.i(TAG, "onPanelAnchored");
}

@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
    _slideUpPane.collapsePane();
}

}

I try to use these but I couldn't know how to do it: Android, SlidingPaneLayout and listView ListView in SlidingUpPanel is not scrollable

Was it helpful?

Solution

I found out a very easy solution for this problem: the only change that is needed is to define a new onTouchListener for the ListView.

The change should be like that:

_menuListView.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            int action = event.getAction();
            switch (action) {
            case MotionEvent.ACTION_DOWN:
                // Disallow ScrollView to intercept touch events.
                v.getParent().requestDisallowInterceptTouchEvent(true);
                break;

            case MotionEvent.ACTION_UP:
                // Allow ScrollView to intercept touch events.
                v.getParent().requestDisallowInterceptTouchEvent(false);
                break;
            }

            // Handle ListView touch events.
            v.onTouchEvent(event);
            return true;
        }
    });

OTHER TIPS

I had been looking into the same problem for a while. Just use the following:

mSlidingPanel.setEnableDragViewTouchEvents(true);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top