【问题标题】:AndroidStudio random whitespace at top of app应用顶部的 Android Studio 随机空白
【发布时间】:2020-09-13 22:24:09
【问题描述】:

我是 Android Studio 的新手,我在启动应用程序时没有在顶部定义这个空白,但在 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>

【问题讨论】:

  • 这个 xml 是 Fragment 还是 Activity 的布局,还是别的什么?
  • 这是一个片段
  • 您能否发布托管此 Fragment 的 Activity 布局的 xml?
  • 我是 Android Studio 的新手,只有一个活动 XML,所以我在上面添加了它

标签: android android-studio mobile-application


【解决方案1】:

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

android:paddingTop="?attr/actionBarSize"

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-17
    • 1970-01-01
    • 2013-05-28
    • 2014-10-16
    • 1970-01-01
    • 2011-11-10
    相关资源
    最近更新 更多