【问题标题】:Android - button height does not changeAndroid - 按钮高度不会改变
【发布时间】:2014-05-20 18:52:07
【问题描述】:

我无法使按钮的高度变小。这是我的 xml 中的内容:

<Button xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/button_small_left"
        style="?android:attr/buttonStyleSmall"
        android:layout_height="10px"
        android:height="10px"
        android:minHeight="10px"
        android:maxHeight="10px"
        android:padding="0px"
        android:textSize="6dip"
        android:text="asd"
/>

在此之后,该按钮仍会以较大的顶部和底部填充显示。文本出现在中间。该按钮在相对布局中使用。

【问题讨论】:

  • 添加android:layout_height="10px" 应该可以完成这项工作。它在我这边工作得很好。你在用什么操作系统...?
  • 从您的 xml 代码中,它对我来说也可以正常工作。您是否忘记了 layout_width:"" 或者您不需要它?
  • 您是否尝试过使用不同的背景颜色为您的元素着色,以确保是按钮元素导致了问题,而不是布局放置?

标签: android button height


【解决方案1】:

而 px(像素)使用 dp(密度像素)作为按钮的高度和宽度。

例如:

android:layout_height="10dp"

对于文本大小,仅使用 sp(缩放索引像素)

android:textSize="6sp"

在您上面的 xml 中,您忘记提供宽度属性。

android:layout_width="40dp"

【讨论】:

    【解决方案2】:

    奇怪 - 当我创建一个新项目再试一次时,这确实工作正常。问题应该出在其他地方。

    【讨论】:

      猜你喜欢
      • 2013-07-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-24
      相关资源
      最近更新 更多