如何消除 Android 应用程序顶部出现的额外间距?

我正在为我的一门大学课程构建 Android 应用程序的主页。我的小组正在使用 Android Studio。我已经有了原来的布局,但我在顶部有一个随机的额外空间,上面写着“欢迎”。

https://img4.mukewang.com/64d349740001f35d01700316.jpg

我不知道如何摆脱顶部的随机间距,它正在将我的其余对象向下推(报告列表在导航栏下方消失)


这是我的fragment_home.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:layout_width="match_parent"

    android:layout_height="match_parent">


    <EditText

        android:id="@+id/editText"

        android:layout_width="365dp"

        android:layout_height="wrap_content"

        android:text="@string/home_welcome"

        android:textAlignment="center"

        android:textSize="20pt"

        app:layout_constraintBottom_toTopOf="@+id/text_appts"

        app:layout_constraintEnd_toEndOf="parent"

        app:layout_constraintStart_toStartOf="parent"

        app:layout_constraintTop_toTopOf="parent" />


    <EditText

        android:id="@+id/text_appts"

        android:layout_width="365dp"

        android:layout_height="55dp"

        android:ems="10"

        android:text="@string/title_appointments"

        android:textSize="14pt"

        app:layout_constraintBottom_toTopOf="@+id/recycler_appts"

        app:layout_constraintEnd_toEndOf="parent"

        app:layout_constraintStart_toStartOf="parent"

        app:layout_constraintTop_toBottomOf="@+id/editText" />


    <androidx.recyclerview.widget.RecyclerView

        android:id="@+id/recycler_appts"

        android:layout_width="360dp"

        android:layout_height="125dp"

        app:layout_constraintBottom_toTopOf="@+id/text_chats"

        app:layout_constraintEnd_toEndOf="parent"

        app:layout_constraintHorizontal_bias="0.484"

        app:layout_constraintStart_toStartOf="parent"

        app:layout_constraintTop_toBottomOf="@+id/text_appts"

        app:layout_constraintVertical_bias="0.226" />


</androidx.constraintlayout.widget.ConstraintLayout>


慕森卡
浏览 146回答 2
2回答

幕布斯6054654

在您的activity_main.xml文件中,尝试删除android:paddingTop="?attr/actionBarSize"ConstraintLayout 中的行,因为没有 actionBar。

噜噜哒

在您的activity_main.xml中将'fragment'(nav_host_fragment)layout_width和layout_height更改为0dp。这是使用约束的正确形式。&nbsp;<fragment &nbsp;&nbsp;&nbsp;&nbsp;android:id="@+id/nav_host_fragment" &nbsp;&nbsp;&nbsp;&nbsp;android:name="androidx.navigation.fragment.NavHostFragment" &nbsp;&nbsp;&nbsp;&nbsp;android:layout_width="0dp" &nbsp;&nbsp;&nbsp;&nbsp;android:layout_height="0dp" &nbsp;&nbsp;&nbsp;&nbsp;app:defaultNavHost="true" &nbsp;&nbsp;&nbsp;&nbsp;app:layout_constraintBottom_toTopOf="@id/nav_view" &nbsp;&nbsp;&nbsp;&nbsp;app:layout_constraintLeft_toLeftOf="parent" &nbsp;&nbsp;&nbsp;&nbsp;app:layout_constraintRight_toRightOf="parent" &nbsp;&nbsp;&nbsp;&nbsp;app:layout_constraintTop_toTopOf="parent" &nbsp;&nbsp;&nbsp;&nbsp;app:navGraph="@navigation/mobile_navigation"&nbsp;/>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java