Umano SlidingPanel中状态栏下方的滑动布局 [英] Sliding layout below status bar in Umano SlidingPanel

查看:99
本文介绍了Umano SlidingPanel中状态栏下方的滑动布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用 https://github.com/umano/AndroidSlidingUpPanel 实现了UmanoSlidingPanel。除了滑动面板展开后,滑动内容(sliding_view)移到状态栏下方,一切都正常。如何避免?我尝试删除

I have implemented UmanoSlidingPanel using https://github.com/umano/AndroidSlidingUpPanel . Everything is working fine except that my sliding panel when expanded, the sliding content (sliding_view) is going below the status bar. How can I avoid that?I tried removing

 <item name="android:windowTranslucentStatus">true</item> 

来自styles.xml,但这也使状态栏对于主要内容也不透明。有什么办法解决这个问题?

from styles.xml but that makes the status bar non-tranlucent for the main content also. Any way to fix this?

<com.sothree.slidinguppanel.SlidingUpPanelLayout xmlns:sothree="http://schemas.android.com/apk/res-auto"
    android:id="@+id/sliding_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="bottom"
    sothree:umanoDragView="@+id/firstPanelDragArea"
    sothree:umanoPanelHeight="@dimen/bottom_panel_height"
    sothree:umanoShadowHeight="4dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <include
            android:id="@+id/toolbar"
            layout="@layout/toolbar" />

        <FrameLayout
            android:id="@+id/frame_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </LinearLayout>

    <!-- SLIDING LAYOUT -->
    <LinearLayout
        android:id="@+id/firstPanelDragArea"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <include layout="@layout/sliding_view" />

    </LinearLayout>

styles.xml

styles.xml

 <style name="AppTheme" parent="@style/Theme.AppCompat">
    <item name="windowActionBar">false</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowTranslucentNavigation">true</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:windowTranslucentStatus">true</item>
    <item name="windowNoTitle">true</item>
</style>

编辑

  public void onPanelSlide(View panel, float slideOffset) {
              if (slideOffset > 0.5 && !flagTransparent) {
                getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
                getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
                flagTransparent = true;
                Log.i(TAG, "onPanelSlide, offset " + slideOffset);
            } else if (slideOffset < 0.5 && flagTransparent){
                getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
                getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
                flagTransparent = false;
                Log.i(TAG, "onPanelSlide, offset " + slideOffset);
  }


推荐答案

找到了解决该问题的另一种方法通过更改SlidingUpPanelLayout.java的onMeasure方法。将代码发布给以后的读者。需要添加4行代码。

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

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

这篇关于Umano SlidingPanel中状态栏下方的滑动布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆