我已經添加了BottomAppBarand BottomNavigationViewwithFloatingActionButton insideConstraintLayout但白色條帶顯示在整個應用程式的螢屏底部。在此螢屏上,使用 來添加導航抽屜Drawerlaout,并Framelayout用于此目的。現在很難管理所有這些組件。
所以,請檢查下面的代碼并幫助我解決這個 UI 問題。
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout 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:id="@ id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="right"
android:fitsSystemWindows="true"
android:gravity="right"
tools:openDrawer="end">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@ id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.appcompat.widget.Toolbar
android:id="@ id/toolbar"
android:layout_width="match_parent"
android:layout_height="45dp"
android:background="@color/colorPrimaryDark"
android:elevation="5dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_constraintTop_toTopOf="parent"
app:titleTextColor="@color/White"
tools:layout_editor_absoluteX="0dp" />
<include
android:id="@ id/header"
layout="@layout/header_layout" />
<FrameLayout
android:id="@ id/home_fragment_container"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/header"
app:layout_constraintBottom_toTopOf="@id/layout_constraint"></FrameLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@ id/layout_constraint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/White"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@ id/layout_coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/White">
<com.google.android.material.bottomappbar.BottomAppBar
android:id="@ id/bottom_app_bar"
style="@style/Widget.MaterialComponents.BottomAppBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:backgroundTint="@color/lighter_gray"
app:fabAlignmentMode="center"
app:fabCradleMargin="7dp"
app:fabCradleRoundedCornerRadius="7dp" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@ id/navigation"
android:layout_width="match_parent"
android:layout_height="85dp"
android:layout_gravity="bottom"
android:background="@android:color/transparent"
android:paddingTop="30dp"
app:itemBackground="@android:color/transparent"
app:itemIconTint="@drawable/tab_color"
app:itemTextColor="@drawable/tab_color"
app:labelVisibilityMode="labeled"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/bottom_navigation_menu" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@ id/fab_options"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:backgroundTint="@color/colorPrimary"
app:fabSize="auto"
app:layout_anchor="@ id/bottom_app_bar"
app:layout_anchorGravity="center|top"
app:srcCompat="@drawable/ic_baseline_add" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.navigation.NavigationView
android:id="@ id/navview"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="end|right"
android:background="@color/White"
android:fitsSystemWindows="true"
android:paddingLeft="20dp"
android:paddingRight="20dp"
app:headerLayout="@layout/nav_header"
app:itemBackground="@android:color/transparent"
app:itemIconTint="@color/background_gray"
app:itemTextColor="@color/background_gray"
app:menu="@menu/drawer_menu" />
</androidx.drawerlayout.widget.DrawerLayout>
我正在添加 UI 問題的螢屏截圖:

uj5u.com熱心網友回復:
我們的問題是您明確指定了 的寬度和FloatingActionButton高度引數,而它不能采用任何寬度/高度。app:fabSize引數指定 fab 的 3 種尺寸:auto、mini 和 normal。
保留layout_width和layout_height為 wrap_content,并使用app:fabSize="normal"(或串列中的其他引數)指定所需的晶圓廠尺寸。
此外,制作BottomNavigationView'sheight wrap_content,因為 fab 有一些內部填充。
為了在封閉布局之外繪制子級,適用android:clipChildren="false"于封閉的 ViewGroup。
uj5u.com熱心網友回復:
您無法洗掉此填充,但可以通過向BottomAppBar.
這樣做,您可能會在 的右側和左側遇到工件BottomNavigationView,以修復此 Add 0dpElevation 到BottomNavigationView.
額外說明:
- 從 中洗掉約束,
BottomNavigationView因為它沒有包含在ConstraintLayout - 您可以洗掉
ConstraintLayout包裝 的CoordinatorLayout,因為它是ViewGroup不需要的額外內容。
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout 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:id="@ id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="right"
android:fitsSystemWindows="true"
android:gravity="right"
tools:openDrawer="end">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@ id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.appcompat.widget.Toolbar
android:id="@ id/toolbar"
android:layout_width="match_parent"
android:layout_height="45dp"
android:background="@color/colorPrimaryDark"
android:elevation="5dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_constraintTop_toTopOf="parent"
app:titleTextColor="@color/White"
tools:layout_editor_absoluteX="0dp" />
<include
android:id="@ id/header"
layout="@layout/header_layout" />
<FrameLayout
android:id="@ id/home_fragment_container"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/header"
app:layout_constraintBottom_toTopOf="@id/layout_constraint"></FrameLayout>
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@ id/layout_coordinator"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="@android:color/transparent"
app:layout_constraintBottom_toBottomOf="parent">
<com.google.android.material.bottomappbar.BottomAppBar
android:id="@ id/bottom_app_bar"
style="@style/Widget.MaterialComponents.BottomAppBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:backgroundTint="@color/lighter_gray"
app:elevation="10dp"
app:fabAlignmentMode="center"
app:fabCradleMargin="7dp"
app:fabCradleRoundedCornerRadius="7dp" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@ id/navigation"
android:layout_width="match_parent"
android:layout_height="85dp"
android:layout_gravity="bottom"
android:background="@android:color/transparent"
android:paddingTop="30dp"
app:elevation="0dp"
app:itemBackground="@android:color/transparent"
app:itemIconTint="@drawable/tab_color"
app:itemTextColor="@drawable/tab_color"
app:labelVisibilityMode="labeled"
app:menu="@menu/bottom_navigation_main" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@ id/fab_options"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:backgroundTint="@color/colorPrimary"
app:fabSize="auto"
app:layout_anchor="@ id/bottom_app_bar"
app:layout_anchorGravity="center|top"
app:srcCompat="@drawable/ic_baseline_add" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.navigation.NavigationView
android:id="@ id/navview"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="end|right"
android:background="@color/White"
android:fitsSystemWindows="true"
android:paddingLeft="20dp"
android:paddingRight="20dp"
app:headerLayout="@layout/nav_header"
app:itemBackground="@android:color/transparent"
app:itemIconTint="@color/background_gray"
app:itemTextColor="@color/background_gray"
app:menu="@menu/drawer_menu" />
</androidx.drawerlayout.widget.DrawerLayout>
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/342891.html
標籤:安卓 安卓布局 android协调器布局 android-bottomappbar android-底部导航视图
上一篇:Butterknife@BindView中的AnnotationTypeMismatchException與在另一個檔案夾結構中定義的布局
下一篇:Android多行純文本背景
