Android布局(1)--线性布局(LinerLayout)

来源:互联网 发布:企业工商数据api 编辑:程序博客网 时间:2024/05/01 16:05
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>



0 0
原创粉丝点击