LinearLayout的android:layout_gravity 定义了子View的对齐方式可以有下面几种:

  • top: 和父容器的顶端对齐,不对子View进行缩放。
  • bottom: 和父容器的底端对齐,不对子View进行缩放。
  • left: 和父容器的左端对齐,不对子View进行缩放。
  • right: 和父容器的右端对齐,不对子View进行缩放。
  • center_vertical: 将子View居中(垂直居中),不对子View进行缩放。
  • fill_vertical: 将子View的垂直方向拉伸充满容器。
  • center_horizontal: 将子View居中(水平居中),不对子View进行缩放。
  • fill_horizontal: 将子View的水平方向拉伸充满容器。
  • center: 将子View居中(水平和垂直都居中),不对子View进行缩放。
  • fill: 将子View水平和垂直方向都拉伸充满整个容器。
  • clip_vertical:垂直裁剪子View
  • clip_horizontal: 水平裁剪子View。

多种选项可以使用“|” 隔开。

本例对三个子View都使用bottom 对齐方式,应为Linerlayout缺省采用baseline 对齐,因此三个View文字基准线是对齐的。

<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:orientation=”horizontal”
android:layout_width=”match_parent”
android:layout_height=”match_parent”>

<TextView
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_marginRight=”3dip”
android:layout_gravity=”bottom”
android:text=”@string/baseline_2_label” />

<Button
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_marginRight=”3dip”
android:layout_gravity=”bottom”
android:text=”@string/baseline_2_button” />

<TextView
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_gravity=”bottom”
android:textSize=”20sp”
android:text=”@string/baseline_2_bigger” />

</LinearLayout>

Layouts->Baseline->2. Bottom_第1张图片" src="https://img.it610.com/image/info5/d6ea57ab667c407aabfb726f532ad305.jpg" width="332" height="493" style="border:1px solid black;">

更多相关文章

  1. Android(安卓)textview文字两端对齐,中间空白
  2. 【Android(安卓)开发】:UI控件之 ImageView 实现图片旋转和缩放功
  3. android动画的透明度渐变、旋转动画、缩放动画、评议动画
  4. android 图片压缩工具类
  5. android图片压缩处理,并保存
  6. Android(安卓)工具类大全java文件
  7. Android使用SubsamplingScaleImageView完美查看超大图片
  8. Android(安卓)调用相册 拍照 实现系统控件缩放 切割图片 .
  9. Android(安卓)的 Relative Layout 常量

随机推荐

  1. Android学习笔记(七)-XML解析与生成:SAX、DO
  2. 简易android通讯录
  3. Android中Looper简介
  4. Android实例剖析笔记(二)
  5. Android开发指南--0 总览
  6. Android布局文件的属性值解析
  7. [转]android解析XML总结
  8. Android(安卓)Service
  9. Android-x86-6.0定制之路 - 辛酸路开始
  10. Android(安卓)Studio 出现 Gradle's depe