底部导航栏遮挡了视图的一部分

6
在我的应用中,我想展示一张简单的图片,
在我的三星Galaxy S7真机上,图片效果良好,底部导航栏不是视图的一部分,而是手机本身。整张图片都可见。
在Android模拟器中,底部导航栏是视图的一部分,图片被部分遮挡。
以下是我的简单线性布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout         
    xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:fitsSystemWindows="true"
          android:background="@color/md_blue_50"
          android:orientation="vertical">

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

    <ImageView
        android:id="@+id/photo_image_large"
        android:adjustViewBounds="true"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="fill_vertical"
        android:scaleType="fitXY"/>

</LinearLayout>

以下是 Android 模拟器的截图:

Android 模拟器

以下是我三星 Galaxy 真机的截图:

Android 真机

在应用程序中的 RecyclerView 中也存在问题,在 Android 模拟器上,图像的底部部分被裁剪了...

3个回答

5

这是因为android:fitSystemWindows被设置为false,将其改为true即可解决问题。


1

我曾经遇到过与BottomNavigationView(菜单)类似的问题,以下是解决方案:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_activity_main_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

<FrameLayout
    android:id="@+id/main_activity_container"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1">  
</FrameLayout>


<android.support.design.widget.BottomNavigationView
    android:id="@+id/navigation"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="start"
    app:itemIconTint="@color/color_main_white"
    app:itemTextColor="@color/color_main_white"
    app:menu="@menu/bottom_navigation_menu"/> 

尝试将参数android:layout_height更改为0dp,并为ImageView添加android:layout_weight="1"。


0

你必须将视图放置在底部导航栏上方,以便视图不会隐藏在底部导航栏中。


但是底部导航栏甚至不是视图的一部分 - 请参考我的LinearLayout... - Andy Cass
是的,我明白了,它是一个安卓模拟器,不是真实设备,所以当你将应用程序放在Play商店中时没有问题。 - Dina Gar
刚刚尝试了android:fitsSystemWindows="false",但图片仍然没有变化。 - Andy Cass
请发布屏幕截图。 - Dina Gar

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接