简体   繁体   English

Android:ConstraintLayout 高度大于模拟器屏幕高度

[英]Android: ConstraintLayout height is bigger than emulator screen's height

I have a problem with ConstraintLayout height in any AndroidStudio emulator.我在任何 AndroidStudio 模拟器中都有 ConstraintLayout 高度问题。 When I run the app in several devices, I am seeing well all the layout rendering.当我在多个设备上运行该应用程序时,我可以很好地看到所有布局渲染。 But, when I run the app in the emulator, the bottom menu is out of range.但是,当我在模拟器中运行应用程序时,底部菜单超出范围。

My activity_main.xml has a ConstraintLayout with a WebView and a BottomNavigationView.我的activity_main.xml有一个带 WebView 和 BottomNavigationView 的 ConstraintLayout。 This is my template:这是我的模板:

template code and design image模板代码和设计图像

<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <WebView
        android:id="@+id/main_webview"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintBottom_toTopOf="@id/bottom_navigation"
        app:layout_constraintTop_toTopOf="parent" />

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottom_navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/color_action_bar"
        app:elevation="16dp"
        app:itemIconTint="@color/color_iconos_bottom_bar"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toBottomOf="@id/main_webview" />

</androidx.constraintlayout.widget.ConstraintLayout>

When I run my app in the emulator, the menu is out of the screen.当我在模拟器中运行我的应用程序时,菜单不在屏幕上。 I can see the top part of the menu, but the icons are below the screen limit.我可以看到菜单的顶部,但图标低于屏幕限制。 When I do a click in that small region of the menu, I can navigate.当我点击菜单的那个小区域时,我可以导航。 So, in conclusion, the menu is there, but out of the limits.所以,总而言之,菜单在那里,但超出了限制。

emulator rendering image模拟器渲染图像

When I run the app in the device, I can see the menu perfectly fitted.当我在设备中运行应用程序时,我可以看到菜单完美匹配。 I downloaded the same model and SDK version emulator than the devices that I have, but I am still seeing it wrong.我下载了与我拥有的设备相同的 model 和 SDK 版本的模拟器,但我仍然认为它是错误的。

So, the problem is that the ConstraintLayout height is bigger than the emulator screen's height.所以,问题是 ConstraintLayout 的高度大于模拟器屏幕的高度。 Can you give me any solution to this problem?你能给我任何解决这个问题的方法吗?

I think the problem is caused by that.我认为问题是由它引起的。 app:elevation="16dp"应用程序:海拔=“16dp”

The problem is that you have conflict constraints, you link the WebView bottom to top of Navigation and top of Navigation to bottom of WebView .问题是您有冲突约束,您将WebView底部链接到Navigation顶部,并将 Navigation 顶部链接到WebView底部。

Remove the link on Navigation to bottom of WebView .删除NavigationWebView底部的链接。

I added the property android:layout_marginBottom="45dp" to the BottomNavigationView element, and now the menu appears in the emulator.我将属性android:layout_marginBottom="45dp"添加到BottomNavigationView元素,现在菜单出现在模拟器中。 But in the device there is a black range below the menu.但在设备中,菜单下方有一个黑色范围。 It seems that the ConstraintLayout's height is 45dp's bigger than the emulator screen height.似乎 ConstraintLayout 的高度比模拟器屏幕高度大 45dp。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM