如何删除Android中按钮周围的填充?

新手上路,请多包涵

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

在预览版和手机上,它看起来像:

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

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

原文由 omega 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 633
2 个回答

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

在 Button 元素上,添加:

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

或者以您的按钮样式:

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

原文由 D. A. Terre 发布,翻译遵循 CC BY-SA 3.0 许可协议

我的解决方案是将 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"/>

原文由 sochas 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题