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

常用属性:

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. 扩展HtmlHelper

    eg3:扩展HtmlHelper                                扩展方法类 1 public static class HtmlExtension 2 { 3 /// ...

  2. ie6不支持png图片的解决办法

    在head里引入png.js文件 <!--[if lte IE 6]> <script type="text/javascript" src="js/P ...

  3. HTML的DOM和浏览器的BOM

    DOM和BOM的区别 HTML DOM 的 document 是 BOM 的 window 对象的属性之一: 通过可编程的对象模型,JavaScript 获得了足够的能力来创建动态的 HTML. Ja ...

  4. IOS应用在iPhone5和iPhone5s上不能全屏显示,应用画面上下各有1条黑色的解决方案

    设置启动图片就可以了: 添加启动图: 接着设置为启动图: 这样就ok了

  5. I.MX6 mkuserimg.sh hacking

    /*********************************************************************** * I.MX6 mkuserimg.sh hackin ...

  6. Linux网络协议栈(三)——网络设备(2)

    2.1.网络设备的注册与注销注册网络设备发生在下列情形: (1)加载网卡驱动程序   网卡驱动程序如果被编译进内核,则它在启动时被初始化,在运行时被作为模块加载.无论初始化是否发生,所以由驱动程序控制 ...

  7. 网络抓包工具wireshark and tcpdump 及其实现基于的libpcap

    最近无意中看到博客园中一篇介绍wireshark的文章,写得不错,它简单清楚介绍了wireshark的使用 简介 wireshark以前叫做Ethereal, 在大学时候的网络课程中就常看到它,它是世 ...

  8. jquery 3D云

    http://www.jq22.com/jquery-info1325 http://demo.jq22.com/jquery-cloud-141217202931 下载地址: http://www. ...

  9. E20180305-hm-xa

    raw adj. 生的,未加工的; 无经验的; 新近完成的; 发炎的,疼痛的; payload n. 有效载荷; (航天器.卫星的) 装备; (车辆等的) 装载货物; (炸弹.导弹的) 爆炸力;

  10. python 面向对象六 类属性和实例属性

    一.实例属性 Python是动态语言,根据类创建的实例可以任意绑定属性. >>> class Student(object): ... def __init__(self, name ...