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" - ...
随机推荐
- getting “fatal: not a git repository: '.'” when using post-update hook to execute 'git pull' on another repo
Here is the script that ultimately worked. I think the bit I was originally missing that prevented i ...
- #Leet Code# Divide Two Integers
描述:不使用 * / % 完成除法操作.O(n)复杂度会超时,需要O(lg(n))复杂度. 代码: class Solution: # @return an integer def dividePos ...
- C# this.Invoke()的作用和用法(摘)
Invoke()的作用是:在应用程序的主线程上执行指定的委托.一般应用:在辅助线程中修改UI线程( 主线程 )中对象的属性时,调用this.Invoke(); 在多线程编程中,我们经常要在工作线程 ...
- JAVA面试题相关基础知识
1.面向对象的特征有哪些方面 ①抽象: 抽象就是忽略一个主题中与当前目标无关的那些方面,以便更充分地注意与当前目标有关的方面.抽象并不打算了解全部问题,而只是选择其中的一部分,暂时不用部分细节 ...
- LA 3904
一道DP题: 一共有三种砖,1*2,2*1,2*2,然后要你铺满整个n*2的地板,求不重复的铺法数: 方法: 首先计算了不考虑对称的情况,然后计算只考虑对称的情况: 所以结果就是(不考虑对称数+只考虑 ...
- JPA2.1 中三个提升应用性能的新功能
经常在网上看到开发者们抱怨 JPA 性能低下的帖子或文章,但如果仔细查看这些性能问题,常会发现导致问题的根本原因大致包括以下几个: 使用过多的 SQL 查询从数据库中获取所需的实体信息,即我们常说的n ...
- Greg and Array
Codeforces Round #179 (Div. 2) C:http://codeforces.com/problemset/problem/296/C 题意:给你一个序列,然后有两种操作,第一 ...
- windows 版Tomcat 7.0的配置
http://hi.baidu.com/liguohei/item/d6ea23ff904f98753d198b24 测试成功,截图 ~~~~~~~~~~~~~~~ 一.安装JDK 1.7 1.添加环 ...
- Lua常用的数据结构表示
1.矩阵 Lua中有两种表示矩阵的方法,一是“数组的数组”.也就是说,table的每个元素是另一个table.例如,可以使用下面代码创建一个n行m列的矩阵:mt = {} -- cr ...
- Java中类Exchaner浅析
Exchaner用于实现两个人之间的数据交换,每个人在完成一定的事物后想与对方交换数据,第一个先拿出数据的人将一直等待第二个人拿着数据到来时,才能彼此交换数据. 张孝祥老师在讲解Exchaner时的比 ...