滑动面板布局监听器实现。二级布局可见性问题

时间:2017-10-03 15:52:43

标签: android slidingpanelayout

我正在使用umano https://github.com/umano/AndroidSlidingUpPanel的向上滑动面板。我面临一个轻微而愚蠢的问题,但我无法修复它。滑动面板的辅助布局具有文本视图。当我通过向上拖动来展开它时,我希望textView减慢淡入淡出并消失(如在SoundCloud音乐应用程序中)。当我向下拖动它时,textView应该再次可见。如何解决?我尝试了很多,但我失败了。[![在此处输入图像说明] [1]] [1]

向上滑动标有红色的面板。

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

1 个答案:

答案 0 :(得分:4)

尝试使用它:

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

        SongNameSlide.setAlpha(slideOffset);
        ArtistNameSlide.setAlpha(slideOffset);
        buttonabc.setAlpha(slideOffset);
    }

由于我不知道它将完全打开哪些值,如果它根据需要正好相反,请以这种方式使用 - > SongNameSlide.setAlpha(1 - slideOffset);