Android中的线性布局(LinearLayout)

来源:互联网 发布:指南针软件使用教程 编辑:程序博客网 时间:2024/06/14 10:40
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />

</LinearLayout>

解释上面代码的意思:

  <LinearLayout>标签:定义了整个程序显示的布局。

  在LinearLayout布局中,android:orientation用于定义布局中子元素的排列方式,布局包含两种排列方式:vertical(垂直排列)和horizontal(水平排列)。

 android:layout_width   定义了元素布局的宽度,可以通过三种方式来指定宽度。

      1)fill_parent:宽度和父元素相同;

      2)wrap_content:宽度随组件本身的内容调整;

      3):通过指定px值来设置宽度。

android:layout_height   定义了元素布局的高度,可以通过三种方式来指定高度。

     1)fill_parent:宽度和父元素相同;

      2)wrap_content:宽度随组件本身的内容调整;

      3):通过指定px值来设置宽度。



原创粉丝点击