Android关闭底部的全屏视图,使其脱离屏幕 [英] Android closing full screen view at the bottom is shunted off the screen

查看:118
本文介绍了Android关闭底部的全屏视图,使其脱离屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个屏幕,其底部的工具栏使用以下样式对齐

I have a screen with a bottom toolbar aligned using the following styling

<style name="BottomToolbar" >
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:background">@color/WHITE</item>
    <item name="android:layout_gravity">bottom</item>
    <item name="android:layout_alignParentBottom">true</item>
    <item name="android:minHeight">?attr/actionBarSize</item>
</style>

当我第一次进入屏幕时,工具栏与屏幕底部对齐.

When I first enter my screen the toolbar is nicely aligned to the bottom of the screen.

但是,如果我进入全屏模式(隐藏工具栏),然后返回到普通模式(重新显示工具栏),则工具栏现在会稍微离开屏幕.看起来好像是向下移动了全屏模式下隐藏的状态栏的数量.

However, If I go to full screen mode (which hides the toolbar) and then return to normal mode (which re-displays the toolbar) the toolbar is now placed slightly off the screen. It looks as if its shifted down the amount of the status bar that is hidden in full screen mode.

如果我将我的应用程序设为背景,然后将其前台显示,则底部工具栏将正确呈现.

If I background my app and then foreground it, the bottom toolbar is rendered correctly.

我在屏幕顶部有一个栏(而不是appBar),它显示在正确的位置.我不知道为什么它放错了底部的工具栏.

I have a bar at the top of the screen (instead of an appBar) and that is rendered in the correct place. I can not work out why it is misplacing the bottom toolbar.

就好像在确定父级的底部时,它不再针对屏幕高度不足的事实进行调整.

Its as if when it is determining the bottom of the parent it is not adjusting for the fact its not full screen height anymore.

我尝试过的事情

退出全屏模式时,我已经尝试在工具栏上设置"fitsSystemWindows ="true",但这没有什么不同.

I have tried setting "fitsSystemWindows="true"" on my toolbar when exiting full screen mode but that doesn't make a difference.

我尝试将工具栏隐藏时设置为不可见"而不是消失",但这没什么区别.

I have tried setting the toolbar to INVISIBLE rather than GONE when hiding it but that makes no difference.

编辑1-添加了有关如何进入和退出全屏模式的代码段

我使用以下内容进入全屏显示

I go into full screen using the following

getActivity().getWindow().getDecorView().setSystemUiVisibility(
      View.SYSTEM_UI_FLAG_LAYOUT_STABLE
    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
    | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
    | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
    | View.SYSTEM_UI_FLAG_FULLSCREEN
    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);

我使用以下代码退出全屏显示

I exit full screen by using the following code

getActivity().getWindow().getDecorView().setSystemUiVisibility(
    View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);

编辑2-视图未从底部移开,其高度过小

似乎底视图没有从屏幕底部移开,它的高度缩小了并且比应该的要小.

It appears that the bottom view is not shoved off the bottom of the screen, its height is shrunk and smaller than it should be.

底部视图是一个LinearLayout,其高度设置为"wrap_content",但由于高度短于其内容,因此似乎无法正确计算高度,因此该内容的底部被切除.

The bottom view is a LinearLayout with its height set to "wrap_content" but it appears the height is not calculated correctly as its shorter than its contents and hence the bottom of its contents are cut off.

编辑3-问题所在的设备

进一步的调查显示,该问题仅出现在没有屏幕导航栏的设备上.例如,问题出在我的Samsung 10平板电脑上,而不是我的Nexus 5x.

Further investigation showed the issue only presents on devices which do not have the on screen navigation bar. For example the issue is on my Samsung 10" Tablet but not on my Nexus 5x.

推荐答案

如果我删除以下标志,则该问题似乎已解决

If I remove the following flag the issue appears to be fixed

View.SYSTEM_UI_FLAG_LAYOUT_STABLE

此标志的Google文档为"使用其他布局标志时,我们希望获得给fitSystemWindows(Rect)的内容插图的稳定视图." https://developer.android.com/reference/android/view/View. html

The Google doc for this flag is "When using other layout flags, we would like a stable view of the content insets given to fitSystemWindows(Rect)." https://developer.android.com/reference/android/view/View.html

医生说 "您可能还需要使用SYSTEM_UI_FLAG_LAYOUT_STABLE来帮助您的应用维持稳定的布局." ( https://developer.android.com/training/system-ui/status .html )和 "最好包含其他系统UI标志(例如SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION和SYSTEM_UI_FLAG_LAYOUT_STABLE),以防止在隐藏和显示系统栏时调整内容的大小."(

The docs say "You may also need to use SYSTEM_UI_FLAG_LAYOUT_STABLE to help your app maintain a stable layout." (https://developer.android.com/training/system-ui/status.html) and "It's good practice to include other system UI flags (such as SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION and SYSTEM_UI_FLAG_LAYOUT_STABLE) to keep the content from resizing when the system bars hide and show." (https://developer.android.com/training/system-ui/immersive.html)

这篇关于Android关闭底部的全屏视图,使其脱离屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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