【问题标题】:Android | Java | How to remove default margins from relative layout?安卓 |爪哇 |如何从相对布局中删除默认边距?
【发布时间】:2021-07-18 11:29:58
【问题描述】:

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

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

已尝试解决方案

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

以上解决方案在我的场景中没有太大帮助。我尝试了另一种解决方案,它是编辑dimens.xml,但是我似乎无法在任何地方找到它。我使用默认具有约束布局的android studio 4.1.3。因此,dimens.xml 不是由项目生成的。但是,如果它不是由项目生成的,那么RelativeLayout 是如何获得利润的呢?

我们将不胜感激。

【问题讨论】:

    标签: android android-relativelayout default-value


    【解决方案1】:

    我已经设法解决了您的问题,我认为 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>
    

    谢谢

    【讨论】:

      猜你喜欢
      • 2016-11-19
      • 2022-06-15
      • 2021-09-01
      • 1970-01-01
      • 2012-10-12
      • 2013-11-23
      • 2021-12-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多