简体   繁体   English

从Android按钮上删除边距

[英]Remove margin from Android buttons

How can I remove the default margin Android buttons are using? 如何删除Android按钮使用的默认边距? I want the buttons to have full width (no space at all between the edge of the screen and the button) and no space between them. 我希望按钮具有全宽度(屏幕边缘和按钮之间完全没有空间),并且它们之间也没有空间。 I am not setting any padding but they seem to have one. 我没有设置任何填充,但是它们似乎只有一个。

I am using "Theme.AppCompat.Light.NoActionBar" as my app theme parent. 我将“ Theme.AppCompat.Light.NoActionBar”用作我的应用程序主题父级。

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</LinearLayout>

屏幕截图显示了默认的安卓按钮边距

在xml按钮中按以下方式使用,然后更改此更改的其他功能,以使其显示方式。

style="?android:attr/buttonBarButtonStyle"

I had the same problem. 我有同样的问题。 The default button comes with margins. 默认按钮带有边距。 Set a button property like this: 设置这样的按钮属性:

android:layout_marginTop="-3dp"

Do the same for the left, right, and bottom margins. 对左,右和下边距执行相同的操作。 Or define a new drawable with these parameters: 或使用以下参数定义一个新的drawable:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle"
    android:padding="10dp"
    >
    <solid android:color="@color/colorButtonGray"/>
    <corners
        android:bottomRightRadius="2dp"
        android:bottomLeftRadius="2dp"
        android:topLeftRadius="2dp"
        android:topRightRadius="2dp"/>
</shape> 

The custom shape will not have any built in margins. 自定义形状将没有任何内置边距。

您可以使用android:minHeight = 0 android:minWidth = 0从按钮中删除多余的空白。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM