问题描述
我有一个包含布局的底板。并且该布局具有相对布局。其中有默认边距。即使我将边距设置为 0dp,它也不起作用。
bottom_sheet_back.xml
<?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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@drawable/blue_back"/>
</RelativeLayout>
里面的代码 activity_main.xml
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:elevation="10dp"
android:padding="0dp">
<com.google.android.material.bottomappbar.BottomAppBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom">
<include layout="@layout/bottom_sheet_back"/>
</com.google.android.material.bottomappbar.BottomAppBar>
这给了我这样的结果。
其中 bottom_sheet_back.xml 具有全宽。
尝试过的解决方案
以上解决方案在我的场景中没有多大帮助。我尝试了另一种解决方案,它是编辑 dimens.xml
但是,我似乎无法在任何地方找到它。我使用默认情况下具有约束布局的 android studio 4.1.3。因此,dimens.xml
不是由项目生成的。但是,如果它不是由项目生成的,那么 RelativeLayout
是如何获得利润的?
任何帮助将不胜感激。
解决方法
我设法解决了您的问题,我认为BottomAppbar 存在问题,但是如果您更改为BottomNavigationView,它运行良好,没有问题,它会删除默认边距
这是我使用的底部导航的代码
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom">
<include layout="@layout/bottom_sheet_back"/>
</com.google.android.material.bottomnavigation.BottomNavigationView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
谢谢