【背景】

此处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

android:layout_above

Positions the bottom edge of this view above the given anchor view ID.

android:layout_alignBaseline

Positions the baseline of this view on the baseline of the given anchor view ID.

android:layout_alignBottom

Makes the bottom edge of this view match the bottom edge of the given anchor view ID.

android:layout_alignEnd

Makes the end edge of this view match the end edge of the given anchor view ID.

android:layout_alignLeft

Makes the left edge of this view match the left edge of the given anchor view ID.

android:layout_alignParentBottom

If true, makes the bottom edge of this view match the bottom edge of the parent.

android:layout_alignParentEnd

If true, makes the end edge of this view match the end edge of the parent.

android:layout_alignParentLeft

If true, makes the left edge of this view match the left edge of the parent.

android:layout_alignParentRight

If true, makes the right edge of this view match the right edge of the parent.

android:layout_alignParentStart

If true, makes the start edge of this view match the start edge of the parent.

android:layout_alignParentTop

If true, makes the top edge of this view match the top edge of the parent.

android:layout_alignRight

Makes the right edge of this view match the right edge of the given anchor view ID.

android:layout_alignStart

Makes the start edge of this view match the start edge of the given anchor view ID.

android:layout_alignTop

Makes the top edge of this view match the top edge of the given anchor view ID.

android:layout_alignWithParentIfMissing

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.

android:layout_below

Positions the top edge of this view below the given anchor view ID.

android:layout_centerHorizontal

If true, centers this child horizontally within its parent.

android:layout_centerInParent

If true, centers this child horizontally and vertically within its parent.

android:layout_centerVertical

If true, centers this child vertically within its parent.

android:layout_toEndOf

Positions the start edge of this view to the end of the given anchor view ID.

android:layout_toLeftOf

Positions the right edge of this view to the left of the given anchor view ID.

android:layout_toRightOf

Positions the left edge of this view to the right of the given anchor view ID.

android:layout_toStartOf

Positions the end edge of this view to the start of the given anchor view ID.

至于每个都是什么效果,就可以自己去多试试就知道了。

Android中RelativeLayout的字符水平(垂直居中)对齐的更多相关文章

  1. CSS3中flexbox如何实现水平垂直居中和三列等高布局

    最近这些天都在弥补css以及css3的基础知识,在打开网页的时候,发现了火狐默认首页上有这样一个东西.

  2. css水平垂直居中对齐方式

    1.文字或者内联元素的垂直水平居中对齐 css属性 -- 水平居中:text-aligin:center; 垂直居中: line-height:height; 例子:. html: <div c ...

  3. CSS制作水平垂直居中对齐

    作为前端攻城师,在制作Web页面时都有碰到CSS制作水平垂直居中,我想大家都有研究过或者写过,特别的其中的垂直居中,更是让人烦恼.这段时间,我收集了几种不同的方式制作垂直居中方法,但每种方法各有千秋呀 ...

  4. 微信小程序文字水平垂直居中对齐问题

    我们知道常用的居中对齐方式有很多种例如: text-align:center; align-items:center; justify-content: center; margin: auto; # ...

  5. CSS制作水平垂直居中对齐 多种方式各有千秋

    作为前端攻城师,在制作Web页面时都有碰到CSS制作水平垂直居中,我想大家都有研究过或者写过,特别的其中的垂直居中,更是让人烦恼.这段时间,我收 集了几种不同的方式制作垂直居中方法,但每种方法各有千秋 ...

  6. CSS中怎么设置元素水平垂直居中?

    记录怎么使用text-align与vertical-align属性设置元素在容器中垂直居中对齐.text-align与vertical-align虽然都是设置元素内部对齐方式的,但两者的用法还是有略微 ...

  7. Android中RelativeLayout和LinearLayout性能分析

    先看一些现象吧:用eclipse或者Android studio,新建一个Activity自动生成的布局文件都是RelativeLayout,或许你会认为这是IDE的默认设置问题,其实不然,这是由 a ...

  8. Android中RelativeLayout各个属性的含义

    android:layout_above="@id/xxx"  --将控件置于给定ID控件之上android:layout_below="@id/xxx"  - ...

  9. Android中RelativeLayout属性详细说明

    android:layout_above="@id/xxx"  --将控件置于给定ID控件之上android:layout_below="@id/xxx"  - ...

随机推荐

  1. linux无法umount解决方案

    [root@995120-master ~]# umount /drbd/ umount: /drbd: device is busy.(In some cases useful info about ...

  2. 练习2 G题 - 数值统计

      Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   Description 统计给 ...

  3. 使用URLClassLoader类载入类实例

    Tomcat当中在接受到要调用的Servlet请求后,需要载入相应的Servlet类,然后创建Servlet类实例,从而调用Servlet类实例的service()方法 下面实例的场景,request ...

  4. BZOJ 1876 SuperGCD

    Description Sheng bill有着惊人的心算能力,甚至能用大脑计算出两个巨大的数的GCD(最大公约数)!因此他经常和别人比赛计算GCD.有一天Sheng bill很嚣张地找到了你,并要求 ...

  5. [Codeforces Round #296 div2 D] Clique Problem 【线段树+DP】

    题目链接:CF - R296 - d2 - D 题目大意 一个特殊的图,一些数轴上的点,每个点有一个坐标 X,有一个权值 W,两点 (i, j) 之间有边当且仅当 |Xi - Xj| >= Wi ...

  6. matlab中元胞数组(cell)转换为矩阵

    matlab中元胞数组(cell)转换为矩阵. cell转换为矩阵函数为:cell2mat(c),其中c为待转换的元胞数组: 转化之后的矩阵可能不满足我们对矩阵维数的要求,那么也许还需要下面两个函数: ...

  7. 纯CSS实现delay连续动画

    从前css3还没出来的时候,用jquery的delay方法可以串起一个一个独立的动画片段. 那么在不使用jquery的平台上,如何借助css3来完成一些列动作呢? 有高人做了一个动感十足的人物动画: ...

  8. 用正则式判断URL是否合法-python

    import sys import re #Make sure we have a single URL argument. if len(sys.argv) != 2: print (sys.std ...

  9. vim下如何删除某行之后的所有行

    使用dG进行删除 在命令模式下将光标置于要删除的起始行,然后依次输入d,G

  10. android 判断程序是首次(第一次)进入

    很多时候,我们需要判断用户是不是第一次进入程序,以决定是不是给用户一些操作提示. 这种功能的实现,说到底还是将数据(一个标志位)存储起来,下次进入程序的时候读取数据进行判断. 我这里只给出一种较简单的 ...