4

When I used SlidingUpPanelLayout, I have to set two children layout (main and panel). When the second layout (the panel) is opened, I want to close it using a Button. But I couldn't find the method.

What is the method?

Andrew T.
  • 4,701
  • 8
  • 43
  • 62
NewDI_Summer
  • 43
  • 1
  • 3

3 Answers3

12

LAST VERSION AT THE BOTTOM

If I understand you well, you want to implement a listener when the second view is opened right?

The way to do that would be like this:

first declare an SlidingUpPanelLayout:

SlidingUpPanelLayout layout;

then, initialize it in onCreate()

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

After, that if you want, you can set its children clickable by:

layout.setEnableDragViewTouchEvents(true);  

Now, the important part is this one. Adding the listener to the layout

 layout.setPanelSlideListener(new PanelSlideListener() {

        @Override
        public void onPanelSlide(View panel, float slideOffset) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onPanelCollapsed(View panel) {
            // TODO Auto-generated method stub
            //Anything you put here is going to happen if the view is closed
        }

        @Override
        public void onPanelExpanded(View panel) {
            // TODO Auto-generated method stub
            //Anything you put here is going to happen if the view is open
        }

        @Override
        public void onPanelAnchored(View panel) {
            // TODO Auto-generated method stub

        }
    });

I hope this helps! Happy coding!

EDIT: If you want to close and/or open the pane, there are two boolean methods within the class:

layout.collapsePane(true); //to close
layout.expandPane(true); //to open

EDIT. Current Version Link to example

layout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED); //to close
layout.setPanelState(SlidingUpPanelLayout.PanelState.EXPANDED); //to open
Luis Lavieri
  • 4,064
  • 6
  • 39
  • 69
  • You are welcome! Please, approve the answer if you are satisfied with it. – Luis Lavieri Apr 03 '14 at 04:26
  • Perfect. That is the way :) – Luis Lavieri Apr 03 '14 at 04:32
  • 1
    as of version 3.0.0 use layout.setPanelState(SlidingUpPanelLayout.PanelState) method – vir us Apr 26 '15 at 15:43
  • @Luis : need your help on this http://stackoverflow.com/q/37154986/5209982 Thanks :) – VipiN Negi May 11 '16 at 06:50
  • @VipiNNegi I am sorry. It's been a while, and the library seemed to have changed their methods. So, my answer here is obsolete. If I get some time tonight, I'll try to set up a working example for you. Check out [this](https://github.com/umano/AndroidSlidingUpPanel/blob/master/demo/src/main/java/com/sothree/slidinguppanel/demo/DemoActivity.java) example that Umano has on their github. It starts on line `86`. Maybe, it will help you out. – Luis Lavieri May 11 '16 at 13:46
1

This one is for the latest version of com.sothree.slidinguppanel:library

  1. Declare the SlidingUpPanelLayout

    SlidingUpPanelLayout mSlideUpPanel;

  2. Initialize it :

    mSlideUpPanel = (SlidingUpPanelLayout) findViewById(R.id.slidingUpPanel);

  3. for the listener:

    mSlideUpPanel.addPanelSlideListener(new SlidingUpPanelLayout.PanelSlideListener() { @Override public void onPanelSlide(View panel, float slideOffset) {

            }
    
            @Override
            public void onPanelStateChanged(View panel, SlidingUpPanelLayout.PanelState previousState, SlidingUpPanelLayout.PanelState newState) {
    
            }
        });
    
0

With new version use setFadeOnClickListener

 /**
     * Provides an on click for the portion of the main view that is dimmed. The listener is not
     * triggered if the panel is in a collapsed or a hidden position. If the on click listener is
     * not provided, the clicks on the dimmed area are passed through to the main layout.
     *
     * @param listener
     */
    public void setFadeOnClickListener(View.OnClickListener listener) {
        mFadeOnClickListener = listener;
    }
navalkishoreb
  • 533
  • 2
  • 8
  • 16