【问题标题】:When setting a background color on a button's style, it changes the margins在按钮样式上设置背景颜色时,它会更改边距
【发布时间】:2014-12-09 06:26:34
【问题描述】:

如果我设置了背景颜色,使用这种风格的按钮之间的边距会比没有它的时候小很多。为什么?我该如何解决这个问题?

<style name="RemoteButton">

    <!-- Leaving this in makes the buttons very close together, without it, the margins increase -->
    <item name="android:background">#d6d7d7</item>

    <item name="android:layout_width">0dp</item>
    <item name="android:layout_height">match_parent</item>
    <item name="android:textColor">#556699</item>
    <item name="android:textSize">20dp</item>
    <item name="android:layout_margin">3dp</item>
</style>

【问题讨论】:

  • 您是否尝试过设置 android:includeFontPadding="false" 因为每种字体都有自己的自定义填充。检查并回复

标签: android android-layout android-studio android-xml android-ui


【解决方案1】:

默认按钮样式不是颜色,它是具有内部填充/边距的可绘制资源 (@android:drawable/btn_default)。有一些关于它的信息here,但相关的并不多。我会进一步研究 android 样式及其工作原理。

至于如何解决,我会看here

【讨论】:

    【解决方案2】:

    在按钮之间添加其他颜色的视图。 或者选择一张没有填充按钮的图片作为背景。 使按钮非常接近的原因是您使用颜色作为背景,然后,如果没有边距,颜色将填充您的按钮小部件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-05-10
      • 2014-02-01
      • 2015-06-04
      • 1970-01-01
      • 1970-01-01
      • 2014-12-21
      相关资源
      最近更新 更多