Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

About com.sothree.slidinguppanel.SlidingUpPanelLayout

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?

like image 238
NewDI_Summer Avatar asked Dec 12 '22 06:12

NewDI_Summer


2 Answers

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
like image 79
Luis Lavieri Avatar answered Dec 13 '22 21:12

Luis Lavieri


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) {
    
            }
        });
    
like image 23
Om Prakash Agrahari Avatar answered Dec 13 '22 21:12

Om Prakash Agrahari