Android中RelativeLayout的字符水平(垂直居中)对齐
【背景】
此处Android中显示出来的TextView中的内容,水平中间不对其。
想要实现水平居中对齐。
【折腾过程】
1.搜:
android RelativeLayout horizontal center
参考:
android – TextView horizontal center in RelativeLayout – Stack Overflow
试过了:
android:layout_centerHorizontal="true"
但没用。
2.后来看到:
relativelayout – Android Relative Layout Align Center – Stack Overflow
去试了试:
android:layout_centerVertical="true"
才明白:
我上面是错误的搜了horizontal ,实际上该去搜Vertical才对。
现在效果是所需要的了:

【总结】
想要水平居中对齐,则只需要去设置:
android:layout_centerVertical="true"
即可。
【引申】
更多的其他参数,可以去官网:
RelativeLayout.LayoutParams | Android Developers
中找到:
|
Attribute Name |
Related Method |
Description |
|
Positions the bottom edge of this view above the given anchor view ID. |
||
|
Positions the baseline of this view on the baseline of the given anchor view ID. |
||
|
Makes the bottom edge of this view match the bottom edge of the given anchor view ID. |
||
|
Makes the end edge of this view match the end edge of the given anchor view ID. |
||
|
Makes the left edge of this view match the left edge of the given anchor view ID. |
||
|
If true, makes the bottom edge of this view match the bottom edge of the parent. |
||
|
If true, makes the end edge of this view match the end edge of the parent. |
||
|
If true, makes the left edge of this view match the left edge of the parent. |
||
|
If true, makes the right edge of this view match the right edge of the parent. |
||
|
If true, makes the start edge of this view match the start edge of the parent. |
||
|
If true, makes the top edge of this view match the top edge of the parent. |
||
|
Makes the right edge of this view match the right edge of the given anchor view ID. |
||
|
Makes the start edge of this view match the start edge of the given anchor view ID. |
||
|
Makes the top edge of this view match the top edge of the given anchor view ID. |
||
|
If set to true, the parent will be used as the anchor when the anchor cannot be be found for layout_toLeftOf, layout_toRightOf, etc. |
||
|
Positions the top edge of this view below the given anchor view ID. |
||
|
If true, centers this child horizontally within its parent. |
||
|
If true, centers this child horizontally and vertically within its parent. |
||
|
If true, centers this child vertically within its parent. |
||
|
Positions the start edge of this view to the end of the given anchor view ID. |
||
|
Positions the right edge of this view to the left of the given anchor view ID. |
||
|
Positions the left edge of this view to the right of the given anchor view ID. |
||
|
Positions the end edge of this view to the start of the given anchor view ID. |
至于每个都是什么效果,就可以自己去多试试就知道了。
Android中RelativeLayout的字符水平(垂直居中)对齐的更多相关文章
- CSS3中flexbox如何实现水平垂直居中和三列等高布局
最近这些天都在弥补css以及css3的基础知识,在打开网页的时候,发现了火狐默认首页上有这样一个东西.
- css水平垂直居中对齐方式
1.文字或者内联元素的垂直水平居中对齐 css属性 -- 水平居中:text-aligin:center; 垂直居中: line-height:height; 例子:. html: <div c ...
- CSS制作水平垂直居中对齐
作为前端攻城师,在制作Web页面时都有碰到CSS制作水平垂直居中,我想大家都有研究过或者写过,特别的其中的垂直居中,更是让人烦恼.这段时间,我收集了几种不同的方式制作垂直居中方法,但每种方法各有千秋呀 ...
- 微信小程序文字水平垂直居中对齐问题
我们知道常用的居中对齐方式有很多种例如: text-align:center; align-items:center; justify-content: center; margin: auto; # ...
- CSS制作水平垂直居中对齐 多种方式各有千秋
作为前端攻城师,在制作Web页面时都有碰到CSS制作水平垂直居中,我想大家都有研究过或者写过,特别的其中的垂直居中,更是让人烦恼.这段时间,我收 集了几种不同的方式制作垂直居中方法,但每种方法各有千秋 ...
- CSS中怎么设置元素水平垂直居中?
记录怎么使用text-align与vertical-align属性设置元素在容器中垂直居中对齐.text-align与vertical-align虽然都是设置元素内部对齐方式的,但两者的用法还是有略微 ...
- Android中RelativeLayout和LinearLayout性能分析
先看一些现象吧:用eclipse或者Android studio,新建一个Activity自动生成的布局文件都是RelativeLayout,或许你会认为这是IDE的默认设置问题,其实不然,这是由 a ...
- Android中RelativeLayout各个属性的含义
android:layout_above="@id/xxx" --将控件置于给定ID控件之上android:layout_below="@id/xxx" - ...
- Android中RelativeLayout属性详细说明
android:layout_above="@id/xxx" --将控件置于给定ID控件之上android:layout_below="@id/xxx" - ...
随机推荐
- Git 基本使用配置
// 1.配置用户名邮箱:用于记录你个人的用户名称和电子邮件地址,用户名可随意修改,git 用于记录是谁提交了更新,以及更新人的联系方式: $ git config --global user.nam ...
- 【原创】Android 对话框的使用
对话框即Dialog .google的官方解释:A dialog is usually a small window that appears in front of the current Acti ...
- easy ui tree 取父节点的值和取蓝色框的值
var nodes = $('#basetree').tree('getChecked'); var cnode = ''; var fnode = ''; for ( var i = 0; i &l ...
- BOM 之 location
BOM 之 location它提供了与当前窗口中加载的文档有关的信息,还提供一些导航功能 .既是 window对象的属性,也是document对象的属性,就是说, window.location 和 ...
- cx_Oracle使用方法一
cx_Oracle使用方法 正确安装好cx_oracle之后,要使用它来连接到oracle数据库进行操作,具体应该分3步走: 第一步:导入cx_Oracle ,建立连接 >>> im ...
- prepare—Article【准备篇】之SSH_tool#PuTTY
第一:下载PuTTY: url : http://www.openssh.com/ 下载界面: 安装后: 详解以上命令 ① ② PuTTYgen is a key generator. It ...
- 转: QtCreator调试程序时GDB崩溃
这个情况出现在QtCreator的2.5版以上,是由于新版QtCreator至少需要7.2 IIRC版的GDB.可以到:http://builds.qt-project.org/job/gdb-win ...
- SQL Server与Oracle中的隔离级别
在SQL92标准中,事务隔离级别分为四种,分别为:Read Uncommitted.Read Committed.Read Repeatable.Serializable 其中Read Uncommi ...
- POJ 1013 Counterfeit Dollar 集合上的位运算
Description Sally Jones has a dozen Voyageur silver dollars. However, only eleven of the coins are t ...
- Contest20140906 ProblemA dp+线段树优化
Problem A 内存限制 256MB 时间限制 5S 程序文件名 A.pas/A.c/A.cpp 输入文件 A.in 输出文件 A.out 你有一片荒地,为了方便讨论,我们将这片荒地看成一条直线, ...