【问题标题】:Why my appbottombar is taking my whole layout height为什么我的 appbottombar 占用了我的整个布局高度
【发布时间】:2020-07-20 14:48:57
【问题描述】:

我在我的 xml 布局中使用此代码我在下面添加了我的布局和一些图像

 ......

    <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:id="@+id/notes_container_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true">

       .......
        <com.google.android.material.floatingactionbutton.FloatingActionButton
            android:id="@+id/add_note_fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/medium_margin"
            android:backgroundTint="@color/colorPrimary"
            app:layout_anchor="@id/bottomAppBar"
            app:srcCompat="@drawable/ic_add_black_24dp"
            tools:ignore="VectorDrawableCompat" />
        <com.google.android.material.bottomappbar.BottomAppBar
            android:id="@+id/bottomAppBar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:backgroundTint="@color/colorPrimary"
            app:hideOnScroll="false"
            app:menu="@menu/appbar_menu"
            app:navigationIcon="@drawable/ic_menu" />

    </androidx.coordinatorlayout.widget.CoordinatorLayout>
</layout>

BottomAppbar 的高度占据了我的整个布局,如图所示

它应该看起来像这张图片

【问题讨论】:

  • 它应该是什么样子的?
  • 我更新了我的帖子以包含图片
  • 发布整个布局
  • 我更新了我的问题

标签: android xml android-layout material-components-android android-bottomappbar


【解决方案1】:

问题不在于BottomAppBar 的维度。
检查您的父布局尺寸或位置:

<androidx.coordinatorlayout.widget.CoordinatorLayout
    android:id="@+id/notes_container_layout"
    android:layout_height="wrap_content"

BottomAppBar 具有正确的高度,但 CoordinatorLayout 使用 android:layout_height="wrap_content"
更改CoordinatorLayout 的高度或在CoordinatorLayout 中使用android:layout_gravity="bottom"

【讨论】:

  • 谢谢。 ? 你救了我的命
猜你喜欢
  • 1970-01-01
  • 2018-10-28
  • 2011-12-03
  • 2022-12-23
  • 2022-08-14
  • 1970-01-01
  • 1970-01-01
  • 2015-09-18
  • 1970-01-01
相关资源
最近更新 更多