您的位置:首页 > 其它

LinearLayout学习笔记

2015-09-28 13:09 176 查看
线性布局分两种,分别是水平线性布局和垂直线性布局,对应设置为android:orientation="horizontal"/"vertical".

  LinearLayout其他XML属性还包括(为列举完全,完整的请参考官方帮助文档):

  android:baselineAligned:是否允许用户调整它内容的基线. (属性值可以设置为true/false,具体请参考/content/4151424.html)

android:gravity:指定如何在该对象中放置此对象的内容(x/y坐标值). android:gravity="top"(buttom、left、right、center_vertical、fill_vertical、center_horizontal、fill_horizontal、center、fill、clip_vertical、clip_horizontal)控制布局中控件的对齐方式。如果是没有子控件的控件设置此属性,表示其内容的对齐方式,比如说TextView里面文字的对齐方式;若是有子控件的控件设置此属性,则表示其子控件的对齐方式,gravity如果需要设置多个属性值,需要使用“|”进行组合. (android:gravity 与 android:layout_gravity的区别 android:gravity是指定本元素的子元素相对它的对齐方式,android:layout_gravity是指定本元素相对于它的父元素的对齐方式.)

   LinearLayout实现效果(嵌套线性布局,最外面为垂直线性布局,里面上半部分水平,下半部分垂直)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">

<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="green"
android:background="#00aa00"
android:layout_weight="1" />

<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="red"
android:layout_weight="1"
android:background="#aa0000"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="blue"
android:layout_weight="1"
android:background="#0000aa"/>
</LinearLayout>

<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="row_one"
android:textSize="15pt"
android:layout_weight="1"/>

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="row_two"
android:textSize="15pt"
android:layout_weight="1"/>

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="row_three"
android:textSize="15pt"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: