从Android按钮中删除边距

时间:2016-07-03 23:13:01

标签: android android-layout user-interface android-theme

如何删除Android按钮正在使用的默认边距?我希望按钮具有全宽(屏幕边缘和按钮之间根本没有空间),并且它们之间没有空间。我没有设置任何填充,但他们似乎有一个。

我正在使用" 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>

Screenshot showing the default margin android buttons have

3 个答案:

答案 0 :(得分:1)

在按钮xml中使用如下所示,然后将其更改的其他功能更改为您希望它们显示的方式。

cicle

答案 1 :(得分:1)

我遇到了同样的问题。默认按钮带有边距。设置如下按钮属性:

android:layout_marginTop="-3dp"

对左,右和下边距执行相同操作。或者使用以下参数定义新的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> 

自定义形状没有任何内置边距。

答案 2 :(得分:-2)

你可以用 机器人:了minHeight = 0 android:minWidth = 0从按钮中删除额外的损失。

相关问题