Android,意外的按钮左右填充

标签 android user-interface

我想制作一个按钮,其中左右上边距和下边距相同。 但我得到这样的东西:

enter image description here

这是一个布局:

<RelativeLayout android:layout_width="match_parent"
                    android:layout_height="wrap_content">
        <TextView android:id="@+id/people_number_label"
                  android:text="@string/number_of_people"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"/>
        <Button
                android:id="@+id/people_number"
                android:layout_toRightOf="@+id/people_number_label"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
    </RelativeLayout>

最佳答案

所以 Button 的工作方式是它是一个带有可绘制背景的 TextView 。那个drawable就是你看到的那个。正如您在此处看到的,文本将在该可绘制对象中居中。如果您希望文本与提示一致,则按钮不适合您。您最好将其设为 TextView 并使用圆角矩形设置可绘制的 xml 背景,使其看起来像一个按钮,但实际上并非如此。

另一件事你可以尝试做align_baseline 两个 View 。这应该对齐文本,但可能会将提示向下推到屏幕上

关于Android,意外的按钮左右填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30946587/

相关文章:

android - 我无法从 Java Mail Api 发送 Yahoo Mail

android - greenDao @ToMany 关系不起作用,返回 0

user-interface - 从操作运行自动化脚本?

mysql - 用于关闭 mysql workbench 中的执行选项卡的键盘快捷方式?

android - 在回收者 View 中加载大量项目

android - 在 React Native 中实现通话录音

android - 为什么 Sensor.TYPE_ROTATION_VECTOR 和 Sensor.TYPE_GAME_ROTATION_VECTOR 为空?

java - 如何将场景生成器中创建的场景加载到JavaFX应用程序主类中?

iphone - performSegueWithIdentifier 不工作

java - 在服务器/客户端程序中发送给所有人与发送给一个人