Android佈局(1)--線性佈局(LinerLayout)

Android應用程序的界面由佈局管理器類和ViewGroup類創建。


線性佈局是所有佈局中最簡單的佈局,它將放入其中的組件按照垂直或水平方向進行排列。在線性佈局中每一行或者每一列只能有一個組件,並且這些組件不會換行。當組件一個一個排列到父窗口的邊緣時候,會自動隱藏剩下的組件。


垂直排列:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:gravity="top|center"
    android:background="#0000FF"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.demo.LinearLayout">
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/button1"
        android:text="進入系統"/>
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/button2"
        android:text="網絡配置"/>
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/button3"
        android:text="退出系統"/>

</LinearLayout>

水平排列:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal"
    android:gravity="top|center"
    android:background="#0000FF"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.demo.LinearLayout">
    <Button
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:id="@+id/button1"
        android:text="進入系統"/>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:id="@+id/button2"
        android:text="網絡配置"/>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:id="@+id/button3"
        android:text="退出系統"/>

</LinearLayout>



發佈了43 篇原創文章 · 獲贊 15 · 訪問量 9萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章