Android API Guides---Linear Layout

来源:互联网 发布:网络靶场 编辑:程序博客网 时间:2024/04/20 10:09
线性布局

LinearLayout中是对齐所有的孩子在一个方向,垂直或水平视图组。您可以指定与Android的布局方向:方向属性。


一个LinearLayout中的所有的孩子都堆叠一前一后,这样一个垂直列表将只有一个孩子每行,不管他们是多么宽,水平列表将会只有一个行高(最高孩子的身高,再加上 填充)。一个的LinearLayout尊重孩子,每个孩子的比重(右,中置,或左对齐)之间的利润。

布局重量
同样加权子
要创建其中每个孩子使用屏幕上的空间相同数量的线性布局,设置了android:每个视图“0dp”(对于垂直布局)或Android的layout_height:layout_width每个视图以“0dp”(对于水平布局)。然后设置了android:每个视图的layout_weight为“1”。
的LinearLayout还支持分配权重,以个别儿童与Android:layout_weight属性。该属性指定在多少空间应该在屏幕上占据一个术语“重要性”价值的一个观点。较大的权重值,使得它扩展到填补父视图的任何剩余空间。子视图可以指定一个权重值,然后在视图组中的任何剩余空间分配给孩子们在他们宣称的重量的比例。默认权重是零。
例如,如果有三个文本字段,其中两个声明权重为1,而其他没有给出体重,体重没有不会增长的第三个文本框,只会占据其内容所需的面积。另外两个同样将扩大,以填补所有三个字段进行测量后剩余的空间。如果第三字段随后给出的(而不是0)2的权重,然后将其现在宣布比其它两个更重要的,所以它得到一半的总的剩余空间,同时前两股的其余部分同样。

<?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:paddingLeft="16dp"    android:paddingRight="16dp"    android:orientation="vertical" >    <EditText        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:hint="@string/to" />    <EditText        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:hint="@string/subject" />    <EditText        android:layout_width="match_parent"        android:layout_height="0dp"        android:layout_weight="1"        android:gravity="top"        android:hint="@string/message" />    <Button        android:layout_width="100dp"        android:layout_height="wrap_content"        android:layout_gravity="right"        android:text="@string/send" /></LinearLayout>
有关到的LinearLayout的每个子视图提供的属性的详细信息,请参阅LinearLayout.LayoutParams。






0 0
原创粉丝点击