android线性布局LinearLayout实例源代码

来源:互联网 发布:linux pr debug 编辑:程序博客网 时间:2024/06/18 18:29

android源代码之线性布局LinearLayout

  线性布局是所有布局中最常用的类之一,也是RadioGroup, TabWidget, TableLayout, TableRow, ZoomControls类的父类。LinearLayout可以让它的子元素垂直或水平的方式排成一行(不设置方向的时候默认按照垂直方向排列)

  下面看一个LinearLayout的例子:别被例子的长度吓住,仔细看一下其实就是一个LinearLayout中放5TextView标签而已,TextView相当于Html标签中的Label

  <?xml version=”1.0″ encoding=”utf-8″?>

  <LinearLayout xmlns:android=”http://android.9tech.cn/”

  android:orientation=”vertical”

  android:layout_width=”fill_parent”

  android:layout_height=”fill_parent”

  android:gravity=”center_horizontal”

  >

  <TextView

  android:layout_width=”fill_parent”

  android:layout_height=”wrap_content”

  android:text=”给小宝宝起个名字:

  android:textSize=”20px”

  android:textColor=”#0ff”

  android:background=”#333″/>

  <TextView

  android:layout_width=”wrap_content”

  android:layout_height=”wrap_content”

  android:text=”遥遥是男孩的小名

  android:textSize=”20px”

  android:textColor=”#0f0″

  android:background=”#eee”

  android:layout_weight=”3″

  />

  <TextView

  android:layout_width=”wrap_content”

  android:layout_height=”wrap_content”

  android:text=”瑶瑶是女孩的小名

  android:textColor=”#00f”

  android:textSize=”20px”

  android:background=”#ccc”

  android:layout_weight=”1″

  />

  <TextView

  android:layout_width=”fill_parent”

  android:layout_height=”wrap_content”

  android:text=”海因是男孩的大名

  android:textColor=”#f33″

  android:textSize=”20px”

  android:background=”#888″

  android:layout_weight=”1″

  />

  <TextView

  android:layout_width=”fill_parent”

  android:layout_height=”wrap_content”

  android:text=”海音是女孩的大名

  android:textColor=”#ff3″

  android:textSize=”20px”

  android:background=”#333″

  android:layout_weight=”1″

  />

  </LinearLayout>

0 0