【背景】

此处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 text horizontal center align

【总结】

想要水平居中对齐,则只需要去设置:

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.

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

更多相关文章

  1. LinearLayout水平居中控制
  2. Android用ViewPager实现多页面的切换效果
  3. Android 滑动效果入门篇(二)
  4. 解决CardView无点击效果,实现水波纹效果
  5. ListView 取消点击效果
  6. Android 字体颜色渐变效果 Span实现
  7. Android手势下拉抽屉效果
  8. Android磨砂效果
  9. LinearLayout中实现水平方向上的两个textview一个居左,一个居右的

随机推荐

  1. android webview 使用
  2. Android(安卓)缩放图片
  3. android Button拖动
  4. 获取Android版本信息和电话信息
  5. Android广播的一些事
  6. 关于Android(安卓)如何配置测试类
  7. android WARNING: Application does not
  8. 转:Android联系人数据库全解析
  9. 解决Eclipse3.6中Android(安卓)代码自动
  10. android studio AndroidManifest.xml命名