线性布局:
线性布局是最简单,Android开发者使用的最多的布局类型之一,开发者用它来组织
用户界面上的控件。线性布局的作用就像他的名字一样:它将控件组织在一个垂直或
水平的形式;

在线性布局中,左右的子元素都按照垂直或水平的顺序在界面上进行排列:
* 如果垂直排列,则:表现的形式为一列多行,且每行只包含一个界面元素;
* 如果水平排列:则:表现的形式为一行多列,且每列只包含一个界面元素;

案例如下:
效果实现:垂直排列,位于屏幕的右下角!





使用说明:
属性 对应方法 描述
android:orientation setOrientation 设置线性布局的朝向,值:horizontal /vertical
android:gravity setGravity(int) 设置线性布局的内部元素的布局方式

给子控件赋权:(layout_weight)
与其他线性布局属性不同,其它属性应用在线性布局视图本身,而layout_weight是应用在在它的
子控件上的。权值本身应该是一个数字(如:0.5 0.25),如果把所有子空间的权值加起来等于1,
子控件的权值控制它在父线性布局中有多“重要”或者留给其多少"空间"

案例如下:
效果实现:垂直排列,按比重0.2 0.5 0.3 进行效果的实现;


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical" >    <!--    效果实现:垂直排列,并在屏幕的右下角     <Button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="Button1" />    <Button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="Button1" />    <Button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="Button1" />    <Button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="Button1" />        -->        <!-- 权值的使用:效果实现,垂直排列  比重:0.2 0.5 0.3 -->    <TextView        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:layout_weight="0.2"        android:background="#F5F5DC"        android:gravity="center"        android:text="权值:0.2\n 水平垂直居中" />    <TextView        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:layout_weight="0.5"        android:background="#00CED1"        android:gravity="center"        android:text="权值:0.5\n 水平垂直居中" />    <TextView        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:layout_weight="0.3"        android:background="#FFD700"        android:gravity="center"        android:text="权值:0.3\n 水平垂直居中" /></LinearLayout>





示例图:

更多相关文章

  1. Android(安卓)fill_parent、wrap_content和match_parent的区别
  2. Android之动态改变布局
  3. (原)Android到IOS开发的转换(一)
  4. Android之解决全屏切换非全屏的页面压缩问题
  5. Android(安卓)Studio 提示与技巧(官方文档翻译)
  6. Android(安卓)自定义控件布局 NullPointerException findViewByI
  7. Android让VideoView填充满屏幕/父布局并保证不变形
  8. Android仿京东首页轮播文字(又名垂直跑马灯)
  9. Android(安卓)(最新)控件透明度,布局透明度,Activity透明度,颜色透

随机推荐

  1. APK的安装过程及原理详解
  2. 【Android】Android 9.0 隐藏虚拟按键跟
  3. [通讯录] android通讯录数据库表解析和添
  4. 随笔10
  5. Android实现发送短信功能实例详解
  6. Android Studio如何配置CURL指令一键打包
  7. Android命令行测试BT,WIFI,Sensor工作状态
  8. Android NDK学习 简介
  9. 去掉Button的默认背景
  10. Android(安卓)App实现仅有横屏切换功能或