线性布局(LinearLayout),线性布局有点想AWT编程里面的FolwLayout,他们都会将容器里面的组件挨个的排列起来。

他们最大的区别在于:Android的线性布局不会换行;AWT里面的FolwLayout则会另起一行进行显示

LinearLayout支持常用XML属性及相关方法的说明

XML属性 相关方法 说明
android:gravity setGravity(int) 设置布局管理器内组件的对齐方式。该属性支持top,bottom,left,right……也可以同时制定多种对齐方式的组合,例如left|center_vertical代表出现在屏幕的左边而且垂直居中。
android:orientation setOrientation(int) 设置布局管理器内组件的排列方式。可以设置为horizontal(水平排列),vertical(垂直排列,默认值)两个的其中一个

XML布局管理器(可以对main.xml中的android:orientation,android:gravity这两个属性进行修改,会有很多显示的结果)

Layout/main.xml

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical"
> <!-- android:orientation="horizontal"水平 ;android:orientation="vertical" 垂直,默认的 -->
<Button
android:id="@+id/bn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/bn1"
/>
<Button
android:id="@+id/bn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/bn2"
/>
<Button
android:id="@+id/bn3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/bn3"
/>
<Button
android:id="@+id/bn4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/bn4"
/>
<Button
android:id="@+id/bn5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/bn5"
/>
</LinearLayout>

GrapHical Layout模式下的效果图:

Values/Strings.xml

 <?xml version="1.0" encoding="utf-8"?>

 <resources>
<string name="bn1">测试按钮1</string>
<string name="bn2">测试按钮2</string>
<string name="bn3">测试按钮3</string>
<string name="bn4">测试按钮4</string>
<string name="bn5">测试按钮5</string>
<string name="bn6">测试按钮6</string>
<string name="app_name">线性布局</string>
</resources>

com.example.linearlayout.MainActivity.java只需要进行一个布局的展示

 package com.example.linearlayout;

 import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build; public class MainActivity extends ActionBarActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main); }
}

Android 自学之线性布局 LinearLayout的更多相关文章

  1. .Net程序猿玩转Android开发---(6)线性布局LinearLayout

                                LinearLayout控件是Android中重要的布局控件,是一个线性控件,所谓线性控件的意思是指该控件里面的内容仅仅能水平或垂直排列.也就 ...

  2. Android学习笔记(11):线性布局LinearLayout

    线性布局LinearLayout是指在横向或是竖向一个接一个地排列.当排列的组件超出屏幕后,超出的组件将不会再显示出来. LinearLayout支持的XML属性和相应方法如表所看到的: Attrib ...

  3. 安卓开发06:布局-线性布局 LinearLayout

    LinearLayout把视图组织成一行或一列.子视图能被安排成垂直的或水平的.线性布局是非常常用的一种布局方式. 请看一个布局例子: <LinearLayout xmlns:android=& ...

  4. 线性布局(LinearLayout)

    线性布局(LinearLayout) 备注 match_parent填充布局单元内尽可能多的空间 wrap_content完整显示控件内容 orientation有两个值,horizontal水平显示 ...

  5. Android——布局(线性布局linearLayout,表格布局TableLayout,帧布局FrameLayout)

    线性布局: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:androi ...

  6. Android布局之线性布局——LinearLayout

    本文将详细介绍线性布局的各种xml属性. xml属性 <?xml version="1.0" encoding="utf-8"?> <Line ...

  7. Android 线性布局 LinearLayout

    垂直布局 vertical <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" ...

  8. 线性布局LinearLayout

    常用属性 id:控件唯一属性 android:id="@+id/ll_1" --------------------------------------- layout_width ...

  9. Android开发之线性布局详解(布局权重)

    布局权重 线性布局支持给个别的子视图设定权重,通过android:layout_weight属性.就一个视图在屏幕上占多大的空间而言,这个属性给其设 定了一个重要的值.一个大的权重值,允许它扩大到填充 ...

随机推荐

  1. MySQL导入数据非常慢的解决办法

    MySQL导出的SQL语句在导入时有可能会非常非常慢,经历过导入仅45万条记录,竟用了近3个小时.在导出时合理使用几个参数,可以大大加快导入的速度. -e 使用包括几个VALUES列表的多行INSER ...

  2. lnmp.org一键安装包

    LNMP安装快速导航:LNMP安装提示,LNMP安装教程.安装失败处理.虚拟主机管理.可选组件.LNMP文件目录说明.状态管理. 系统需求: CentOS/Debian/Ubuntu Linux系统 ...

  3. DP录 (更新)

    补补弱项 全面发展.. 从最基础来 sdut1299最长上升子序 #include <iostream> #include<cstdio> #include<cstrin ...

  4. 用PowerShell批量收回wsp包

    转:http://www.xuebuyuan.com/168334.html 提供wsp部署的参数:$wspnames:路径下的所有wsp文件名用逗号隔开,如"sumhtestwsp.wsp ...

  5. WinForm打印之页边距

    1.启用页边距: 默认情况下PrintDocument是不理会页边距的(MS再次让人无语...),这也是为什么有人说明明设了页边距在打印预览里却没有效果的原因. 解决办法是设置PrintDocumen ...

  6. SQL Server查询性能优化——堆表、碎片与索引(二)

    本文是对 SQL Server查询性能优化——堆表.碎片与索引(一)的一些总结.  第一:先对 SQL Server查询性能优化——堆表.碎片与索引(一)中的例一的SET STATISTICS IO之 ...

  7. POJ 1655 Balancing Act (求树的重心)

    求树的重心,直接当模板吧.先看POJ题目就知道重心什么意思了... 重心:删除该节点后最大连通块的节点数目最小 #include<cstdio> #include<cstring&g ...

  8. git 版本历史

    版本:git rev-parse --git-dir显示Git版本库的位置   --show-cdup显示当前工作区目录的深度  --parseopt解析命令行参数 $ git rev-parse - ...

  9. Extjs中grid行的上移和下移

    一.将up和down按钮放到tbar中,然后选中grid行即可实现上移和下移 var up = new Ext.Action({ text : 'Up', icon : 'up.png',//或者添加 ...

  10. HW4.34

    import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...