【问题标题】:Why is this white space appearing below the appbar layout?为什么这个空白会出现在 appbar 布局下方?
【发布时间】:2020-09-20 15:37:55
【问题描述】:

我不知道是什么导致了空间问题。它必须是一些我不知道的 xml 属性。这是一个很好的片段:

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
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:fitsSystemWindows="true"
android:background="@drawable/bg">

<com.google.android.material.appbar.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fitsSystemWindows="true"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <com.google.android.material.appbar.CollapsingToolbarLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <ImageView
            android:id="@+id/logo_home"
            android:layout_width="match_parent"
            android:layout_height="131dp"
            android:scaleType="centerCrop"
            app:layout_collapseMode="parallax"
            tools:ignore="ContentDescription" />

    </com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

这是另一个出现空格的片段的图像:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/holo_green_dark">

</RelativeLayout>

【问题讨论】:

    标签: android xml android-layout kotlin android-fragments


    【解决方案1】:

    这是 Android 团队的一个错误。 除了希望他们修复它,您无能为力。 除非你自己做。

    【讨论】:

      【解决方案2】:

      如前所述,这是 Android 方面的一个错误。一种解决方案是在线性布局中使用相对布局,并为相对布局分配 10 的权重,使其覆盖整个屏幕:

      <LinearLayout 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"
          android:background="@android:color/holo_green_dark"
          android:weightSum="10">
      
          <RelativeLayout
              android:layout_weight="10"
              android:layout_width="match_parent"
              android:layout_height="0dp">
          </RelativeLayout>
      
      </LinearLayout>
      

      【讨论】:

        【解决方案3】:

        当你添加到你的主活动资源文件时,恰好出现了这个错误:fitsSystemWindows = true。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2022-11-28
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-12-10
          相关资源
          最近更新 更多