代码之家  ›  专栏  ›  技术社区  ›  Jack

RequestLayout不反映使用系统\uI_标志\u隐藏\u导航后的更改

  •  0
  • Jack  · 技术社区  · 6 年前

    我正在使用以下代码/标志隐藏底部导航栏,但问题是我的活动视图没有重新绘制/刷新/重新布局以反映此更改。

    if(android.os.build.version.sdk ou int>=android.os.build.version ou codes.kitkat){
    int uioptions=view.system_ui_flag_hide_navigation_view.system_ui_flag_immersive_sticky;
    view decorview=getwindow().getdecorview();
    decorview.setsystemui可见性(ui选项);
    }
    
    rootRelativeLayout.RequestLayout();
    < /代码> 
    
    

    我的活动代码

    <relativelayout xmlns:tools=“http://schemas.android.com/tools”
    xmlns:android=“http://schemas.android.com/apk/res/android”
    android:id=“@+id/root_relativelayout”
    android:layout_width=“匹配父级”
    android:layout_height=“匹配父级”
    android:fitsSystemWindows=“真”
    android:cliptopadding=“true”>
    
    <相对布局
    android:layout_width=“匹配父级”
    android:layout_height=“包装内容”
    android:layout_AlignParentBottom=“真”
    android:orientation=“水平”>
    
    </relativelayout>
    
    </relativelayout>
    < /代码> 
    
    

    内部relativelayout保持在其位置,就好像导航栏仍然存在一样,即使我在其父级relativelayout上调用了requestlayout(),它也不会落到屏幕的底部。

    正如你在照片中看到的,底部有一个山墙。

    我找到了解决这个问题的方法,但它也会导致另一个问题。

    我想到的解决方案是将android:fitssystemwindows设置为false而不是true。

    但这会导致一个问题,即我的活动的对齐顶部视图位于状态栏的后面,我认为唯一的解决方案是将顶部填充设置为状态栏的高度。

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
       int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
       View decorView = getWindow().getDecorView();
       decorView.setSystemUiVisibility(uiOptions);
    }
    
    RootRelativeLayout.requestLayout();
    

    我的活动代码

    <RelativeLayout xmlns:tools="http://schemas.android.com/tools"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/root_relativelayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        android:clipToPadding="true">
    
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:orientation="horizontal">
    
        </RelativeLayout>
    
    </RelativeLayout>
    

    内部relativelayout保持在它的位置,就好像导航栏仍然存在,并且不会下降到屏幕的底部,即使我在它的父relativelayout上调用了requestlayout()。

    正如你在照片中看到的,底部有一个山墙。 enter image description here

    我找到了这个问题的解决方案,但它也引起了另一个问题。

    我想到的解决方案是设置android:fitsSystemWindows为假而不是真。

    但这会导致一个问题,即我的活动的对齐顶部视图位于状态栏的后面,我认为唯一的解决方案是将顶部填充设置为状态栏的高度。

    1 回复  |  直到 6 年前
        1
  •  0
  •   Jack    6 年前

    对于未来的搜索者,解决方案是将fitsSystemWindows设置为false。

    android:fitsSystemWindows="false"