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

常用属性:

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. 【iOS-Tips】-工具Tip

    [iOS-Tips]-工具Tip 1.Xcode自带头文件的路径 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulato ...

  2. C# MVC 枚举转 SelectListItem

    <span style="font-size: 18px; font-family: Arial, Helvetica, sans-serif; background-color: r ...

  3. 百度面试经历_web前端开发

    百度面试经历_web前端开发 --2016年09月24日校招杭州站 刚面试完,担心过去就忘记掉,故回来时在地铁上用手机码下面试题目,供参考,也留作自己以后的面试参考依据.

  4. spring boot redis缓存入门

    摘要: 原创出处 泥瓦匠BYSocket 下载工程 springboot-learning-example ,工程代码注解很详细.JeffLi1993/springboot-learning-exam ...

  5. The type exists in both DLLs

    2>C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\c0b37647\aaceda91\Ap ...

  6. YTU 2975: 我的编号

    2975: 我的编号 时间限制: 1 Sec  内存限制: 128 MB 提交: 42  解决: 15 题目描述 建立一个学生链表,每个链表结点含有学生的基本信息,编号和姓名.现在n个学生站成一列,根 ...

  7. ACTION中获得数据的几种方式

    1.第一种是通过公司封装的方法. 2.第二种:是通过IF方法判断 3.第三种是通过:set/get获得

  8. poj-1655 Balancing Act(树的重心+树形dp)

    题目链接: Balancing Act Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11845   Accepted: 4 ...

  9. 创建cell的三种方式

    方式一 注册cell -> 无需为cell绑定标识符 [使用UIViewController完成!] l  1> static NSString * const ID = @"c ...

  10. 关于使用kafka时对于大数据消息体是遇到的问题

    kafka对于消息体的大小默认为单条最大值是1M. 但是在我们应用场景中, 常常会出现一条消息大于1M, 如果不对kafka进行配置. 则会出现生产者无法将消息推送到kafka或消费者无法去消费kaf ...