androidslidingpanelayout

Sliding Up Panel Layout Listener implementation. Secondary layout visibility issues


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);
        }
    });

Solution

  • 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);