2011-10-07 93 views
5

我无法让按钮的高度变小。这里是我在我的XML中有:Android - 按钮高度不变

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

在此之后,按钮仍然显示与一个大的顶部和底部填充。文字出现在中间。该按钮在相对布局中使用。

+0

添加'android:layout_height =“10px”'应该在做这个工作。它在我身边工作得很好。你在做什么操作系统...? – SamSPICA

+0

从你的XML代码,它的工作也适合我。你忘了layout_width:“”还是不需要你? – user370305

+0

您是否尝试过使用不同背景颜色对您的元素进行着色,以确保它是导致故障而不是布局的按钮元素? – Drejc

回答

0

奇怪 - 当我创建一个新项目再试一次时,这确实很好。问题应该是其他地方。

0

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

例:

android:layout_height="10dp" 

和文字大小只使用SP(规模指数像素)

android:textSize="6sp" 

在你上面的XML,你忘了给width属性。

android:layout_width="40dp"