Android学习笔记二:(布局)Linear Layout、Layout weight测试

1、LinearLayout是子view均为单方向的,即均为水平或垂直方向的布局。你可以用android:orientation属性来

定义layout方向

所有子view都是一个挨着一个的,所以一个垂直列表,不管它本身多宽,同时只能有一行。若是水平列表,则都等高。

2、LayoutWeight

用来操控各个子view的相对比例,,即各个子元素对空间的使用权重

Weight并非网上很多文章所叙述的那样(文章都过于片面),weight是指某个组件在布局中【剩余空间】中的显示权重,那么所谓的剩余空间又是什么意思呢,其实是在没有设置weight属性的控件优先显示的情况,将未占用的布局空间合理分配给设置过weight的组件

       <EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        android:background="#12ed34"
        android:hint="@string/DealTool" />
       <EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="3"
        android:background="#67bb88"
        android:hint="@string/DealTool" />
       <EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        android:background="#00aa00"
        android:hint="@string/hello_world" />

 测试之后上图。

REF:http://blog.csdn.net/frank_softworks/article/details/7320268

原文地址:https://www.cnblogs.com/gaozy/p/3859715.html