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" - ...
随机推荐
- crontab 基本用法
crontab格式:第1列分钟1-59第2列小时1-23(0表示子夜)第3列日1-31第4列月1-12第5列星期0-6(0表示星期天)第6列要运行的命令 还可以用一些特殊符号: *: 表示任何时刻 , ...
- git推送失败的问题
git报错如下: fatal: 'origen' does not appear to be a git repositoryfatal: The remote end hung up unexpec ...
- C++编译器合成Default Constructor的4种情况
笔记C++编译器为编译器需要合成Default Constructor的4种情况. 1,Class A内含Class B对象,Class A没有Default Constructor时会在编译时合成D ...
- C#获取硬盘空间信息
/// <summary> /// 获取指定驱动器的空间总大小(单位为B) /// </summary> /// <param name="str_HardDi ...
- 《C和指针》章节后编程练习解答参考——第8章
8.1 #include <stdio.h> int main (void) { int a, b, c, d; // 不使用嵌套花括号初始化 unsigned ][][][] = { , ...
- 编程思想—依赖注入(DI)并非实现控制反转(IOC)的最佳方法
以构造函数注入为例: public class TestClass(IClassA a,IClassB b, IClassC C,IClassD d) { public void Method1() ...
- PyCharm如何设置显示行号?
File->setting->Editor->General->Appearance,勾选Show line numbers
- jQuery组件写法
知识点: 什么是插件 jQuery插件的模式 jQuery插件的Lightweight Start模式(入门级插件模式) 8.1 插件(Plug-in) “插件”这个关键字,估计大家在日常生活中经常有 ...
- bzoj 3744: Gty的妹子序列 主席树+分块
3744: Gty的妹子序列 Time Limit: 15 Sec Memory Limit: 128 MBSubmit: 101 Solved: 34[Submit][Status] Descr ...
- c#回调函数写法
添加一个cs文件,在里面定义回调 using System; using System.Collections.Generic; using System.Linq; using System.Web ...