android - 按钮不水平居中

标签 android android-layout android-button

我刚刚开始 Android 开发,我无法弄清楚为什么我的按钮内的文本对齐方式没有水平居中。它垂直居中。

我试过重力、一些填充、中心和文本对齐中心,但没有成功。我在上面使用 RelativeLayoutEditTextTextView。当我从 Activity 中取出其他 View 时,也没有任何变化。

我可以通过重力 center_vertical 和一些填充使其居中,但这种方法似乎不合适。

这是更新前按钮的 View :

更新:在我的 ADV 上针对 android:gravity="center_vertical|center_horizo​​ntal"进行了测试,结果运行良好。似乎是 Eclipse 中图形布局 View 的一个错误,它未对齐按钮 View 的内部上下文。这是它在我的 AVD 上的工作:

enter image description here

最佳答案

设置按钮的重力为android:gravity = "center"或android:gravity = "center_vertical|center_horizo​​ntal"。

关于android - 按钮不水平居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15396841/

相关文章:

java - 如何通过espresso UI测试初始化​​presenter的可为空变量以避免NPE

javascript - 如何强制 16 :9 ratio with getUserMedia on all devices?

android - picasso 图书馆未在 Gingerbread 设备中应用圆形变换

java - Android Textview 中的条件字符串与未评估数据绑定(bind)

android - 保存 EditText 和按钮点击的状态

java - 创建和使用数据库 : Android

android - 编译 android jni 示例时出错 : invalid -march= option: `armv5te'

android - 更改 ListView Item 背景颜色但保留默认选择器样式?

java - Android 应用程序中的停止/播放按钮

android - 如何在android中动态更改按钮的大小