线性布局是一种让视图水平或者垂直布排列的布局;

常用属性:

androuid:orientation :表示布局方向

  • 取值vertical表示垂直布局
  • 取值horizontal表示水平布局

android:gravity 表示视图对齐方式

  • 内容包括 TOP,bottom,left,right,center_vertical,center_horizontal,center
  • 可以使用“|”分割填写多个值

布局中的视图可以使用如下多个属性:

android:layout_gravity 表示单个视图的对齐方式

android:layout_weight 表示单个视图所在大小的比重

  • 当Layout_weight为0时候视图大小自身确定
  • 当layout_weight大于0时,视图在线性布局方向根据比重拉伸

代码演示:

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<Button
android:layout_width="200dp"
android:layout_height="100dp"
android:text="adaflkjn"
android:gravity="bottom|center_horizontal"/> </LinearLayout>

android:gravity:是决定控件内元素在某个位置

<Button
android:layout_width="200dp"
android:layout_height="100dp"
android:text="adaflkjn"
android:layout_gravity="center"/>

android:layout_gravity是本元素在父元素里面显示的位置

weight的应用

<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="sdaf"/>
<Button
android:layout_width="1dp"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="klndgjl"
/>

 <TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="weight为0"
android:background="#FFF0F5"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="weight为1"
android:layout_weight="1"
android:background="#800080"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="weight为4"
android:layout_weight="4"
android:background="#4B0082"
/>

Android基础TOP3:线性布局的特点,常用属性,及权重值的更多相关文章

  1. android基础学习之布局

    我学习android第一步接触的就是布局的学习.布局是androidUI的基础,是重中之重.总的来说android有6种布局,分别是线性布局LinearLayout.相对布局RelativeLayou ...

  2. Android基础TOP3:Activity的线性,相对,帧和表格布局的概括

    线性布局 LinearLayout: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android&q ...

  3. Android 自学之线性布局 LinearLayout

    线性布局(LinearLayout),线性布局有点想AWT编程里面的FolwLayout,他们都会将容器里面的组件挨个的排列起来. 他们最大的区别在于:Android的线性布局不会换行:AWT里面的F ...

  4. 【Android】7.1 布局控件常用的公共属性

    分类:C#.Android.VS2015: 创建日期:2016-02-10 一.简介 Android应用程序中的布局控件都是容器控件,用于控制子元素的排列和放置方式.Android提供的布局控件有: ...

  5. android 59 LinearLayout 线性布局

    ##常见的布局* LinearLayout 线性布局线性布局往左右拉是拉不动的,> 线性布局的朝向 vertical|horizontal> 线性布局的权重 weight 和 0dip一起 ...

  6. Android开发之线性布局详解(布局权重)

    布局权重 线性布局支持给个别的子视图设定权重,通过android:layout_weight属性.就一个视图在屏幕上占多大的空间而言,这个属性给其设 定了一个重要的值.一个大的权重值,允许它扩大到填充 ...

  7. .Net程序猿玩转Android开发---(6)线性布局LinearLayout

                                LinearLayout控件是Android中重要的布局控件,是一个线性控件,所谓线性控件的意思是指该控件里面的内容仅仅能水平或垂直排列.也就 ...

  8. Android之Linearlayouy线性布局

    写了个小例子xml代码如下: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout x ...

  9. android学习之线性布局

    效图如下 移通152余继彪 该布局使用了线性布局完成 父布局为线性布局,黄色和灰色部分为水平的线性布局,剩余50%部分为水平线性布局,该布局中包含了两个垂直的线性布局分别占了三分之1和三分之二

随机推荐

  1. [办公应用]从美国带回来的兄弟牌brother打印机如何处理

    周末帮朋友去调一台国外带回来的brother一体机,型号MFC-J630W.这是她单位老板从国外带回来的,说是便宜:不过她说只有英文说明书,她不太会操作.我想这还不容易么,就满口答应下来了.我先到br ...

  2. Koa2学习(二)async/await

    Koa2学习(二)async/await koa2中用到了大量的async/await语法,要学习koa2框架,首先要好好理解async/await语法. async/await顾名思义是一个异步等待 ...

  3. Vim升华之树形目录插件NERDTree安装图解【转】

    本文转载自:http://www.linuxidc.com/Linux/2013-06/86048.htm 无意中看到实验室的朋友使用的vim竟然能在左边显示树形目录,感觉很方便,这样子文件夹有什么文 ...

  4. HDU - 1863 畅通工程(最小生成树)

    d.m个村庄,n条路,计算出所有村庄畅通需要的最低成本. s.最小生成树 c.Prim算法:cost[a][b]和cost[b][a]都得赋值. /* Prim算法 Prim求MST 耗费矩阵cost ...

  5. POJ - 3308 Paratroopers(最大流)

    1.这道题学了个单词,product 还有 乘积 的意思.. 题意就是在一个 m*n的矩阵中,放入L个敌军的伞兵,而我军要在伞兵落地的瞬间将其消灭.现在我军用一种激光枪组建一个防御系统,这种枪可以安装 ...

  6. 初识Spring Boot框架和快速入门

    前面的铺垫文章已经连着写了六篇了,主要是介绍了spring和SpringMVC框架,小伙伴们在学习的过程中大概也发现了这两个框架需要我们手动配置的地方非常多,不过做JavaEE开发的小伙伴们肯定也听说 ...

  7. Gerrit代码Review实战

    代码审核(Code Review)是软件研发质量保障机制中非常重要的一环,但在实际项目执行过程中,却因为种种原因被Delay甚至是忽略.在实践中,给大家推荐一款免费.开放源代码的代码审查软件Gerri ...

  8. 关于ArcGis for javascript的使用

    1.引用ArcGis for javascript核心类库的两种方式: 1.1.下载js包,解压缩放入项目中 1.1.1.下载核心类库压缩文件, 下载地址: https://developers.ar ...

  9. (转)Repeater中增加序号自增列

    <%# Convert.ToString(Container.ItemIndex+)%> 当Repeater空为时,提示没有数据... <FooterTemplate> < ...

  10. maven仓库错误

    1.jai_core 时间:2018年3月21日10:04:57 URL:https://mvnrepository.com/artifact/javax.media/jai_core/1.1.3 / ...