线性布局(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 sql_slave_skip_counter

    因为mysql的主从复制是逻辑复制,所以slave在apply relay log的过程中,经常会遇到错误,而参数sql_slave_skip_counter可以设置跳过多少个event,让slave ...

  2. Azure Site Recovery:我们对于保障您的数据安全的承诺

    Anoob Backer 云 + Enterprise 项目经理  Azure Site Recovery是一个基于 Azure的全天候.易用的服务,可以安全地安排恢复操作,一旦发生灾难,即可为您 ...

  3. Mac 上Dock中添加“最近打开过的项目”(Recent Applications)

    有一个特别有用的Stack,“最近打开过的项目”,建立方法如下: 1. 打开Terminal,输入以下命令 defaults write com.apple.dock persistent-other ...

  4. App Store 加急审核方式

    https://developer.apple.com/contact/app-store/?topic=expedite 1:理由一般是用户安全问题或者崩溃问题成功率会高一些. 如果是崩溃问题,你最 ...

  5. 2016值得关注的语言平台、JS框架

    语言和平台 Python 3.5 在今年发布了,带来了很多新特性 比如 Asyncio,,为你带来了类似 node.js 的事件机制,还有type hints. 鉴于Python 3 终于真正地火起来 ...

  6. Android使用HttpClient实现文件上传到PHP服务器,并监控进度条

    上传 服务器端PHP 代码如下 : <?php $target_path = "./tmp/";//接收文件目录 $target_path = $target_path.($ ...

  7. POJ-3070Fibonacci(矩阵快速幂求Fibonacci数列) uva 10689 Yet another Number Sequence【矩阵快速幂】

    典型的两道矩阵快速幂求斐波那契数列 POJ 那是 默认a=0,b=1 UVA 一般情况是 斐波那契f(n)=(n-1)次幂情况下的(ans.m[0][0] * b + ans.m[0][1] * a) ...

  8. Mysql常用操作记录

    在linux平台中相关的MySql操作 打开Mysql mysql -uroot -p  //-u后边为用户名,-p后边为密码    1:使用SHOW语句找出在服务器上当前存在什么数据库:mysql& ...

  9. Esper系列(四)Output

    功能 控制Esper事件流计算结果的输入形式.时间点及频率: 格式 1  ";

  10. HW2.18

    public class Solution { public static void main(String[] args) { System.out.println("a" + ...