Sliding Up Panel Layout Listener implementation. Secondary layout visibility issues
Asked Answered
V

1

5

I'm using sliding up panel from umano https://github.com/umano/AndroidSlidingUpPanel. I'm facing a minor and silly issue, but I'm not able to fix it. The sliding panel's secondary layout has a text view. When I expand it by dragging upwards, I want the textView to slowing fade and disappear(as in SoundCloud music app). And when I drag it back down the textView should be visible again. How to fix that? I tried a lot, but I failed.[![enter image description here][1]][1]

Sliding up panel marked in red.

MainActivity.java

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


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

            SongNameSlide.setVisibility(panel.INVISIBLE);
            ArtistNameSlide.setVisibility(panel.INVISIBLE);
            buttonabc.setVisibility(panel.INVISIBLE);

        }

        @Override
        public void onPanelStateChanged(View panel, 
SlidingUpPanelLayout.PanelState previousState, SlidingUpPanelLayout.PanelState newState) {
            if(newState.equals(SlidingUpPanelLayout.PanelState.EXPANDED)&& 
previousState.equals(SlidingUpPanelLayout.PanelState.COLLAPSED)){
                SongNameSlide.setVisibility(panel.GONE);
                ArtistNameSlide.setVisibility(panel.GONE);
                buttonabc.setVisibility(panel.GONE);
                slidingUpPanelLayout.setDragView(panel);


            }

        else {

                SongNameSlide.setVisibility(panel.VISIBLE);
                ArtistNameSlide.setVisibility(panel.VISIBLE);
                buttonabc.setVisibility(panel.VISIBLE);
            }
        }
    });

    slidingUpPanelLayout.setFadeOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

 slidingUpPanelLayout.setPanelState (SlidingUpPanelLayout.PanelState.COLLAPSED);
        }
    });
Vagarious answered 3/10, 2017 at 15:52 Comment(0)
S
8

Add a PanelSlideListener to the sliding panel and the function onPanelSlide() will be called with panel layout and offset values whenever the panel will be moved by the user. You can add it as:

slidingUpPanelLayout.addPanelSlideListener(
    new SlidingUpPanelLayout.PanelSlideListener() {
        @Override
        public void onPanelSlide(View panel, float slideOffset) {
            SongNameSlide.setAlpha(slideOffset);
            ArtistNameSlide.setAlpha(slideOffset);
            buttonabc.setAlpha(slideOffset);
        }
    }
);

Now, you'll get the offset which ranges from 0 to 1 indicating how much the panel has been opened. Use this offset value and set it as alpha of the UI elements you want to hide.

As I don't know for which values it will be fully opened, if it works just opposite as required, use those in this way -> SongNameSlide.setAlpha(1 - slideOffset);

Spiculate answered 3/10, 2017 at 16:43 Comment(4)
ah! There it is! It was so simple. Sorry for my silly question, I,m new to this. By the way may I know what is slideOffset? Is it how far the panel goes?Vagarious
@SebinPaul slideOffset here is the float value which is default in most cases of slider which goes to 1 for full opened and 0 for fully closed so by allocating this value to setAlpha value slowly changes to 0 to 1 or vice-versa and that slowly disappear/appear effect occurs.Spiculate
Nice one! Thank you for your time mate!Vagarious
No problem at all.Spiculate

© 2022 - 2024 — McMap. All rights reserved.