15

So I'm using the Sliding Up Panel Library in my application, and I'm trying to implement a ScrollView inside the sliding panel. Since both the sliding panel and the ScrollView are controlled by vertical scrolls, this is causing me some issues.

I've partially got it to work by switching the panel's dragview once the panel has been slid all the way up, and when the ScrollView has been scrolled to the top.

enter image description here

The problem I'm facing now is that, when scrolling the panel to top the scrolling doesn't transfer to the ScrollView, like it does in Google Maps. Little hard to explain, so look at the video here: www.youtube.com/watch?v=9MUsmQzusX8&feature=youtu.be

This is the panel slide listener:

...
slidePanel.setEnableDragViewTouchEvents(true);
slidePanel.setPanelSlideListener(new SlidingUpPanelLayout.PanelSlideListener() {

    @Override
    public void onPanelSlide(View panel, float slideOffset) {

            // Change the dragview to panelheader when panel is fully expanded
            // I'm doing this here instead of in onPanelExpanded, 
            // because onPanelExpanded first gets called once scroll 
            // is released. 
            if (slideOffset <= 0) {
                slidePanel.setDragView(layoutPanelTop);
            } 

            // If the panel is not fully expanded set the whole 
            // panel as dragview
            else if(slideOffset > 0) {
                slidePanel.setDragView(layoutPanel);
            }
        }
    }

    @Override
    public void onPanelExpanded(View panel) {
        // layout.setDragView(layoutPanelTop);

        panelCollapsed = false;
        panelExpanded = true;
        panelAnchored = false;

        Log.v("TAG, "panelExpanded");

    }

    @Override
    public void onPanelCollapsed(View panel) {
        slidePanel.setDragView(layoutPanel);

        panelCollapsed = true;
        panelExpanded = false;
        panelAnchored = false;

        Log.v(TAG, "panelCollapsed");
    }

    @Override
    public void onPanelAnchored(View panel) {
        slidePanel.setDragView(layoutPanel);

        panelCollapsed = false;
        panelExpanded = false;
        panelAnchored = true;

        Log.v(TAG, "panelAnchored");
    }
});

And I have managed to create a fully working scrollview listener by extending scrollview, which can detect scroll direction and onDown and onUp motion events:

private boolean atScrollViewTop = false;

@Override
public void onScrollChanged(int scrollY) {
    scrollY = Math.min(mMaxScrollY, scrollY);
    if (scrollY <= 0) {
        Log.v("myTag", "You at scrollview top");
        atScrollViewTop = true;

    } else {
        atScrollViewTop = false;
    }
    mScrollSettleHandler.onScroll(scrollY);

    switch (mState) {
        case STATE_SCROLL_UP:
            if (panelExpanded && atScrollViewTop) {
                slidePanel.setDragView(layoutPanel);
            } else {
                slidePanel.setDragView(layoutPanelTop);
            }
            Log.v("myTag", "scrolling up");
            break;
        case STATE_SCROLL_DOWN:
            slidePanel.setDragView(layoutPanelTop);
            Log.v("myTag", "scrolling down");
            break;
    }
}

@Override
public void onDownMotionEvent() {

}

@Override
public void onUpOrCancelMotionEvent() {

}

I've been struggling with this the last two days.. So really hope on some pointer at least. Thanks very much in advance. Regards Jakob Harteg.

JJD
  • 50,076
  • 60
  • 203
  • 339
Jakob Harteg
  • 9,587
  • 15
  • 56
  • 78
  • @Jakob- Actually i have Listview in SlidingUpPanel. There's a button on each listview item. I want to collapse panel on button click on perticular list view item. I think setDragView() is method for collapsing panel. But i can't understand how can i implement in my adapter class? Please tell me how can i do that. Thanks in Advance. – Dhruv Apr 16 '14 at 07:12
  • @Lawrence setDragView() is not the method for collapsing. To Collapse it i think its somthinng like smoothSlideTo(1.0); but not sure. – Jakob Harteg Apr 16 '14 at 16:29
  • But where should i apply smoothSlideTo() method? In custom adapter onClickListner of button, is it true? – Dhruv Apr 17 '14 at 06:27
  • 1
    @Lawrence you should call slidePanel.smoothSlideTo(1.0f, 500); in your onClickListener (where 500 is your velocity) – Jakob Harteg Apr 17 '14 at 12:26
  • 1
    Does this answer your question? [SlidingUpPanelLayout and ScrollView](https://stackoverflow.com/questions/22478361/slidinguppanellayout-and-scrollview) – user4157124 Feb 22 '22 at 21:54
  • Check out this answer (involves some changes to the SlidingUpPanelLayout): https://stackoverflow.com/a/22720204/466937 – Maria Sakharova Oct 13 '14 at 06:04

3 Answers3

7

Sorry for delay.. i find the solution.

image = (ImageView) findViewById(R.id.image); //Layout to slide  

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

layout.setDragView(image); 
/*This method sets the layout to be used only
 in the sliding panel, while all layouts children
 are able to perform other functions such as scrolling */  

And this is the layout

<..SlidingUpPanelLayout
    android:id="@+id/sliding_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:gravity="center" />

        <LinearLayout
            android:id="@+id/slide_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <ImageView 
                android:id="@+id/image"
                android:layout_width="match_parent"
                android:layout_height="35dp"
                android:background="@drawable/ec_image"/>

            <!-- FINALLY SCROLLVIEW -->
            <ScrollView .... />

Hope it is useful.

JJD
  • 50,076
  • 60
  • 203
  • 339
Fabrizio Billeci
  • 572
  • 2
  • 10
  • 18
  • well this is kind of the base of my code, and I am trying to implement a much more complex user experience, than what this offers. But thanks anyways – Jakob Harteg Nov 14 '13 at 08:32
0

I'm guessing ScrollView is child of the SlidingPanel?
In that case, override onInterceptTouchEvent to your SlidingPanel to intercept the onTouch event of your ScrollView when y = 0.

onInterceptTouchEvent does the following two:

  • child gets action cancel event
  • parent get the event trough onTouch
JJD
  • 50,076
  • 60
  • 203
  • 339
Commuze
  • 25
  • 5
  • Still can't get it to work.. could you give me some pointers that are a little more code related (I'm not asking you to write my app, I'm just stuck..). Here is the SlidingPanel's code (https://github.com/umano/AndroidSlidingUpPanel/blob/master/library/src/com/sothree/slidinguppanel/SlidingUpPanelLayout.java) which overrides onInterceptTouchEvent at line 544, it is here I'm suppose to do some sort of modification right? – Jakob Harteg Oct 27 '13 at 20:50
0

I don't know if I've arrived to late but after working hard some days I've found that AndroidSlidingUp panel has a method called setScrollView who handles scroll events properly.

I hope that this post will be useful because I was spending much time searching and I didn't find some tip that help me.

emaleavil
  • 591
  • 7
  • 14