Android Studio - Element 隐藏在智能手机后面

Android Studio - Element is hidden behind smartphone

我在我的网络视图中添加了一个按钮,但该按钮部分隐藏在智能手机后面。

我在下面的截图中画了一个红色的矩形,这是显示的真实尺寸,为什么webview区域比显示尺寸大??我必须将按钮移得更高,这样它才不会显示不出来。

在xCode (iOS) 中有"safe area" 是显示的可见区域,没有状态栏和底部栏,在Android Studio 中有类似的东西吗?

我该如何解决这个问题?

我是运行AndroidStudio 3.4.2

activity_fullscreen.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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:id="@+id/relativeLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:visibility="visible"
    tools:context="de.blizz_z.onlineshop.FullscreenActivity">

    <Button
        android:id="@+id/backButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="32dp"
        android:layout_marginLeft="32dp"
        android:layout_marginBottom="20dp"
        android:text="Zurück"
        app:layout_constraintBottom_toBottomOf="@+id/blizzView"
        app:layout_constraintStart_toStartOf="@+id/blizzView" />

    <WebView
        android:id="@+id/blizzView"
        android:layout_width="412dp"
        android:layout_height="844dp"
        android:keepScreenOn="true"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

    </WebView>

可能是项目的屏幕尺寸与您phone的分辨率不同

尝试为 webview 声明新的布局尺寸,或者您可以在打开 webview 时将按钮可见性设置为 none

btn.setVisibility(View.GONE); 

如果您想在 WebView 上创建按钮,请使用 FrameLayout 作为父级,然后执行如下操作:

<FrameLayout>
<WebView/>
<Button/>
</FrameLayout>

您已将 WebView 的大小设置为任意大小,这可能会超出您设备的屏幕。 Button 约束设置正确,但由于 WebView 的底部不在屏幕上,按钮也不在屏幕上。
尝试改变

    android:layout_width="412dp"
    android:layout_height="844dp"

    android:layout_width="match_parent"
    android:layout_height="match_parent"

这将使 WebView 适合每台设备的全屏,并将 Button 限制在 WebView 的 bottom-left 角。

您正在将 WebView 设置为特定的高度和宽度,如果您想支持多种设备,这是不好的做法。在你的 XML:

<Button
    android:id="@+id/backButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="32dp"
    android:layout_marginLeft="32dp"
    android:layout_marginBottom="20dp"
    android:text="Zurück"
    app:layout_constraintBottom_toBottomOf="@+id/blizzView"
    app:layout_constraintStart_toStartOf="@+id/blizzView" />

<WebView
    android:id="@+id/blizzView"
    android:layout_width="412dp"
    android:layout_height="844dp"
    android:keepScreenOn="true"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

</WebView>

您正在将 WebView 的高度设置为 844dp,这意味着当设备的高度小于此高度时它会过度滚动。同样,您的 Button 被限制为 WebView,当它应该相对于浮动在 WebView 上的父视图时。所以在我看来你应该把 XML 改成这个(粘贴时删除我的评论):

<Button
    android:id="@+id/backButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="32dp"
    android:layout_marginLeft="32dp"
    android:layout_marginBottom="20dp"
    android:text="Zurück"
    app:layout_constraintBottom_toBottomOf="parent" <!-- Constrain to parent, not WebView -->
    app:layout_constraintStart_toStartOf="parent"   <!-- Constrain to parent, not WebView --> />

<WebView
    android:id="@+id/blizzView"
    android:layout_width="match_parent"   <!-- Change from fixed dimension to "match_parent" -->
    android:layout_height="match_parent"  <!-- Change from fixed dimension to "match_parent" -->
    android:keepScreenOn="true"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

</WebView>