2016-07-03 90 views
2

如何删除Android按钮正在使用的默认保证金?我希望按钮具有全部宽度(在屏幕边缘和按钮之间根本没有空间),并且它们之间没有空间。我没有设置任何填充,但他们似乎有一个。删除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

+2

这是来自按钮背景,最有可能的。 – CommonsWare

+0

您是否使用过提供的解决方案之一? – Geoff

+0

试过他们,但他们不工作,因为我想他们。我结束使用自定义涟漪效应作为背景从这里:http://stackoverflow.com/a/26349261/2456568 – Mike

回答

-1

Scale的X方向的按钮:android:scaleX="1.05"

1

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

style="?android:attr/buttonBarButtonStyle" 
-2

你可以使用Android的 :=了minHeight 0 的android:minWidth = 0删除多余的按钮从marging。

+1

这是用来删除填充,而不是边距。 – Abhilash

0

我有同样的问题。默认按钮带有边距。设置一个像这样的按钮属性:

android:layout_marginTop="-3dp" 

对左侧,右侧和底部页边距做同样的操作。或者使用这些参数定义一个新的绘图:

<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> 

自定义形状不会有任何内置页边距。