Sliding layout below status bar in Umano SlidingPanel

后端 未结 3 1141
囚心锁ツ
囚心锁ツ 2021-01-21 09:01

I have implemented UmanoSlidingPanel using https://github.com/umano/AndroidSlidingUpPanel . Everything is working fine except that my sliding panel when expanded, the sliding co

3条回答
  •  余生分开走
    2021-01-21 10:01

    Found another solution to the problem by making changes in onMeasure method of SlidingUpPanelLayout.java . Posting the code for future readers.Need to add 4 lines of code.

    SlidingPanelLayout.java

     @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
        final int widthSize = MeasureSpec.getSize(widthMeasureSpec);
        final int heightMode = MeasureSpec.getMode(heightMeasureSpec);
        final int heightSize = MeasureSpec.getSize(heightMeasureSpec);
    
        if (widthMode != MeasureSpec.EXACTLY) {
            throw new IllegalStateException("Width must have an exact value or MATCH_PARENT");
        } else if (heightMode != MeasureSpec.EXACTLY) {
            throw new IllegalStateException("Height must have an exact value or MATCH_PARENT");
        }
    
        final int childCount = getChildCount();
    
        if (childCount != 2) {
            throw new IllegalStateException("Sliding up panel layout must have exactly 2 children!");
        }
    
        mMainView = getChildAt(0);
        mSlideableView = getChildAt(1);
        if (mDragView == null) {
            setDragView(mSlideableView);
        }
    
        // If the sliding panel is not visible, then put the whole view in the hidden state
        if (mSlideableView.getVisibility() != VISIBLE) {
            mSlideState = PanelState.HIDDEN;
        }
    
        int layoutHeight = heightSize - getPaddingTop() - getPaddingBottom();
        int layoutWidth = widthSize - getPaddingLeft() - getPaddingRight();
    
        // First pass. Measure based on child LayoutParams width/height.
        for (int i = 0; i < childCount; i++) {
            final View child = getChildAt(i);
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
    
            // We always measure the sliding panel in order to know it's height (needed for show panel)
            if (child.getVisibility() == GONE && i == 0) {
                continue;
            }
    
            int height = layoutHeight;
            int width = layoutWidth;
            if (child == mMainView) {
                if (!mOverlayContent && mSlideState != PanelState.HIDDEN) {
                    height -= mPanelHeight;
                }
    
                width -= lp.leftMargin + lp.rightMargin;
            } else if (child == mSlideableView) {
                // The slideable view should be aware of its top margin.
                // See https://github.com/umano/AndroidSlidingUpPanel/issues/412.
     //                height -= lp.topMargin;.
     // START OF CODE CHANGES
                if (height < SCREEN_HEIGHT) {  //SCREEN_HEIGHT = 900
                    height = height - MARGIN_BOTTOM; //MARGIN_BOTTOM = 8
                } else {
                    height = height - getStatusBarHeight();
                }
     // END OF CODE CHANGES
            }
    
    
      public int getStatusBarHeight() {
        int result = 0;
        int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
        result = getResources().getDimensionPixelSize(resourceId);
        }
        return result;
    }
    

提交回复
热议问题