应用顶部的AndroidStudio随机空白

问题描述 投票:-1回答:1

我是Android Studio的新手,这是我在启动应用时未在应用顶部定义的空白,但不是在Android Studio的预览屏幕中定义的空白:

Screenshot of the app in Virtual Device

Screenshot of the preview in Android Studio

我不知道它的来源,因为我的定义XML的顶部没有定义该空格:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/scrollContainer"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <LinearLayout
        android:id="@+id/containerLayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

下面仅是上面显示的两个线性布局。我尝试过仅添加文本,但空格仍然出现。我也没有在代码中添加任何内容来显示此内容。

任何帮助/想法将不胜感激!

编辑:以下是activity_main XML:

    <?xml version="1.0" encoding="utf-8"?>
    <androidx.constraintlayout.widget.ConstraintLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingTop="?attr/actionBarSize">

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/nav_view"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="0dp"
        android:layout_marginEnd="0dp"
        android:background="?android:attr/windowBackground"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:menu="@menu/bottom_nav_menu" />

    <fragment
        android:id="@+id/nav_host_fragment"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:defaultNavHost="true"
        app:layout_constraintBottom_toTopOf="@id/nav_view"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:navGraph="@navigation/mobile_navigation" />
</androidx.constraintlayout.widget.ConstraintLayout>
android android-studio mobile-application
1个回答
1
投票

在activity_main.xml中,尝试删除该行:

android:paddingTop="?attr/actionBarSize"

这将在ConstraintLayout内容周围添加等于操作栏高度的填充,在这种情况下是不需要的。

© www.soinside.com 2019 - 2024. All rights reserved.