在我的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>

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

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

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


当前回答

为我工作过:)

   android:insetTop="0dp"
    android:insetBottom="0dp"
    android:minWidth="0dp"
    android:minHeight="0dp"
    android:padding="0dp"

其他回答

它似乎不是填充,边距,或minheight/width。 设置android:background="@null"按钮失去了触摸动画,但事实证明,设置任何背景都可以修复边界。


我目前正在与:

minSdkVersion 19
targetSdkVersion 23

对我来说,问题是在一些Android主题上的minHeight和minWidth。

在Button元素上,添加:

<Button android:minHeight="0dp" android:minWidth="0dp" ...

或者在你的按钮样式中:

<item name="android:minHeight">0dp</item>
<item name="android:minWidth">0dp</item>

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

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

对< androidx.appcompat.widget.AppCompatButton >

           <androidx.appcompat.widget.AppCompatButton
                .
                .
                android:minHeight="0dp"
                android:minWidth="0dp" 
               >

            </androidx.appcompat.widget.AppCompatButton>