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" - ...
随机推荐
- js获取上传文件信息并及时查看
<form id="picForm" name="picForm" method="post" enctype="mult ...
- C# Winform开发框架模块图(平台核心模块+示例模块)
企业版V4.0 - 模块图 企业版V4.0 - 项目解决方案 Client/Server构架,有两个解决方案: 客户端解决方案说明: 服务端解决方案说明: C/S系统开发框架- ...
- source insight 使用技巧
一.在所有文件中查找字符串 1.菜单栏选择“search project” 2.在随便一个工程文件中把所要查找的字符串输入到空白的地方,然后点连接
- Apriori算法在购物篮分析中的运用
购物篮分析是一个很经典的数据挖掘案例,运用到了Apriori算法.下面从网上下载的一超市某月份的数据库,利用Apriori算法进行管理分析.例子使用Python+MongoDB 处理过程1 数据建模( ...
- 在DJANGO的类视图中实现登陆要求和权限保护
以前接触的是基于函数的保护,网上材料比较多. 但基于类视图的很少. 补上! Decorating class-based views 装饰类视图 对于类视图的扩展并不局限于使用mixin.你也可以使用 ...
- 【POJ2778】AC自动机+矩阵乘法
DNA Sequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14758 Accepted: 5716 Descrip ...
- C++ Unicode SBCS 函数对照表,以备日后查阅(很全)
C++ Unicode SBCS 函数对照表,以备日后查阅 Generic SBCS UNICODE TCHAR char wchar_t _TEOF EOF WEOF _TINT int wint_ ...
- Android List<Map<String,String>转json(例子)
package com.armslee.json.test.cases; import java.util.ArrayList; import java.util.HashMap; import ja ...
- [置顶] linux内核启动2-setup_arch中的内存初始化(目前分析高端内存)
上一篇微博留下了这几个函数,现在我们来分析它们 sanity_check_meminfo(); arm_memblock_init(&meminfo, mdes ...
- 14.6.3.3 Making the Buffer Pool Scan Resistant
14.6.3.3 Making the Buffer Pool Scan Resistant 相比使用一个严格的LRU算法,InnoDB 使用一个技术来最小化数据总量 带入到buffer pool 而 ...