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" - ...
随机推荐
- [Neural Networks] Momentum
一.目的 加快参数的收敛速度. 二.做法 另第t次的权重更新对第t+1次的权重更新造成影响. 从上式可看出,加入momentum后能够保持权重的更新方向,同时加快收敛.通常alpha的取值为[0.7, ...
- VBA开发经验总结之一:利用Range对象设计用户界面
读罢<EXCEL专业开发>,最大的震撼就是著者对VBA技术的追求以及对Excel艺术品般的设计.受到此书著者的启发,也打算把自己在日常开发中一些经验总结出来,一来作为自己的知识储备,二来也 ...
- php 微信支付jsapi
首先你们公司开通微信支付功能后,会收到一份邮件,里面有账户相关信息,一般有:微信支付商户号,商户平台登录帐号,商户平台登录密码,申请对应的公众号,公众号APPID. 1.下载demo:用上面信息登陆& ...
- Pyqt5 实时图像滚动
实时图像 写了一个关于实时图像滚动显示的例子,做个记录. 滚动算法: 难点: 将内存数据绘制到界面,需要用到QImage和QPixmap,使用QImage转换一下,具体参见代码.这个费了好大劲才弄出来 ...
- python for list generate content
content = [ii for ii in range(50)] This can generate a list content
- MAC OX 配置JDK环境变量
大家在windows里面配置JDK环境变量很容易,但是如果要在mac里面配置JDK环境变量和windows里面有所不同,具体如下: 第一: mac OS里面自带jdk,不过是1.6的版本,现在很多人使 ...
- iOS:实现表格填充和选择操作
功能:创建一个列表,用数组填充表格,并支持选择列表行 // // main.m // Hello // // Created by lishujun on 14-8-28. // Copyright ...
- seajs配合spm应用之四弹出框
前面描述了 seajs的弹出遮罩层, 还没讲到弹出框, 这里接着把那几个例子介绍完. 目前已经有的工作是, 点击toggle按钮,可以弹出一个背投一样的暗灰色遮罩层, 主要的作用就是遮住当前页面上所有 ...
- Git fork指令
ork并且更新一个仓库 现在有这样一种情形:有一个叫做Joe的程序猿写了一个游戏程序,而你可能要去改进它.并且Joe将他的代码放在了GitHub仓库上.下面是你要做的事情: fork并且更新GitH ...
- MySQL重置密码与远程连接权限问题
如果mysql没有密码,或者密码设置为空的时候可以通过在用管理员身份打开cmd,然后在里面输入mysqladmin -u root password 123456 这个地方的密码是明文密码. 如果忘 ...