android设置Button字体居中

十里冰香 2011-12-16 06:52:25
android:gravity="center" ;都是这么设置的啊,但是为什么显示的却是居中偏右呢?
...全文
8669 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
goodluckme2013 2012-10-29
  • 打赏
  • 举报
回复
android:gravity描述的是:
Specifies how to align the text by the view's x and/or y axis when the text is smaller than the view.
意思就是说设置文字在view里的对齐方式。你要将button上的文字设置成居中,这样设置的是对的。
如果没有居中看看文字里是不是有空格。
chen_yanhua123 2012-08-23
  • 打赏
  • 举报
回复 1
居左的话 android:gravity="left|center"
居右 android:gravity="right|center"
chen_yanhua123 2012-08-23
  • 打赏
  • 举报
回复
默认就是居中的啊, 不用加任何东西
十里冰香 2011-12-16
  • 打赏
  • 举报
回复
我在想,
<Button
android:id="@+id/news"
android:layout_centerHorizontal="true"
android:text="@string/news"
android:gravity="center"
android:layout_width="100px"
android:layout_height="50px" >
</Button>
这个是不是设置的控件位于父类控件的中间而不是设置字体的。但是不知道有没有设置字体居中的方法

51,397

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧