简体   繁体   English

Android - 按钮高度不会改变

[英]Android - button height does not change

I am unable to make the height of my button smaller. 我无法使我的按钮的高度变小。 Here's what I have in my xml: 这是我在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"
/>

The button still shows up with a big top and bottom padding after this. 在此之后,该按钮仍会显示一个大的顶部和底部填充。 The text appears in the middle. 文字出现在中间。 The button is used inside a relative layout. 该按钮用于相对布局。

Strange - this does work fine when I created a new project to try again. 奇怪 - 当我创建一个新项目再试一次时,这确实很好。 The problem should have been somewhere else. 这个问题应该在其他地方。

Instead px (pixel) use dp(density pixel) for buttons height and width. 相反,px(像素)使用dp(密度像素)作为按钮的高度和宽度。

Ex: 例如:

android:layout_height="10dp"

and for text size use only sp(scale index pixel) 并且对于文本大小仅使用sp(缩放索引像素)

android:textSize="6sp"

In your above xml you forget to give width attribute. 在上面的xml中,你忘了给出width属性。

android:layout_width="40dp"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM