首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >RelativeLayout中的TextView水平中心

RelativeLayout中的TextView水平中心
EN

Stack Overflow用户
提问于 2012-02-03 13:23:58
回答 6查看 78.5K关注 0票数 66

在我的应用程序屏幕上,我想将方向显示为水平居中。我尝试使用下面的布局xml代码

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:layout_marginTop="10dip"
  >
  <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:text="Connections" />
</RelativeLayout>

谢谢

EN

回答 6

Stack Overflow用户

回答已采纳

发布于 2012-02-03 13:28:01

android:gravity控制TextView中的外观。因此,如果您有两行文本,它们将在TextView的边界内居中。试试android:layout_centerHorizontal="true"

票数 150
EN

Stack Overflow用户

发布于 2012-02-03 13:28:11

使用以下命令:

代码语言:javascript
运行
复制
android:layout_centerHorizontal="true"

在TextView中

票数 18
EN

Stack Overflow用户

发布于 2012-02-03 13:38:52

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:layout_marginTop="10dip"
    >
  <TextView
    android:layout_centerHorizontal="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:text="Connections" />
</RelativeLayout>
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9124075

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档