微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

安卓 |爪哇|如何从相对布局中删除默认边距?

如何解决安卓 |爪哇|如何从相对布局中删除默认边距?

我有一个包含布局的底板。并且该布局具有相对布局。其中有认边距。即使我将边距设置为 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>

这给了我这样的结果。

result

其中 bottom_sheet_back.xml 具有全宽。

bottom_sheet_bacck

正如您在第一张图片中看到的,我想删除该边距。

尝试过的解决方

  1. Android UI Default Margin Remove
  2. Android Remove default margins in RelativeLayout

以上解决方案在我的场景中没有多大帮助。我尝试了另一种解决方案,它是编辑 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>

谢谢

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。