在我的Android应用程序中,我有这样的布局:

<?xml version="1.0" encoding="utf-8" ?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical">

    <fragment
         android:id="@+id/map"
         android:layout_width="match_parent"
         android:layout_height="0dp" 
         android:layout_weight="1" 
         class="com.google.android.gms.maps.SupportMapFragment"/>

    <Button
        android:id="@+id/button_back"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:onClick="CloseActivity"
        android:padding="0dp"
        android:text="@+string/back" />

</LinearLayout>

在预览和在手机上,它看起来是这样的:

正如你在底部区域的按钮上看到的,那里有一些填充。

我怎么能摆脱它,让按钮完全填满底部区域?


当前回答

你也可以用layout_width(height)参数来做。

例如,我已经用android:layout_height="18dp"代码删除了顶部和底部空间。

其他回答

我的解决方案是将insetTop和insetBottom属性设置为0。

<android.support.design.button.MaterialButton
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:insetTop="0dp"
        android:insetBottom="0dp"
        android:text="@string/view_video"
        android:textColor="@color/white"/>

我刚接触机器人,但我也遇到过类似的情况。我做了什么@Delyan建议,也使用android:background=“@null”在xml布局文件。

您可以通过将其inset设置为零来实现这一点。

android:insetBottom="0dp"
android:insetTop="0dp"

以编程方式删除AppCompatButton填充:

button.setPadding(0, 0, 0, 0)
button.minHeight = 0
button.minimumHeight = 0

给你的按钮一个自定义背景:@drawable/material_btn_blue