线性布局(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. WIP Job > APP-WIP-25191 or Pending Close

    使用 Close Discrete Jobs (FORM) 关闭工单,有一工单的状态一直为PENDING CLOSE 检查 PENDING MATERIAL TRANSACTION ,PENDING ...

  2. poj2229Sumsets

    http://poj.org/problem?id=2229 挺好的一公式.. #include <iostream> #include<cstdio> #include< ...

  3. 部署解决方案包 (SharePoint Server 2010)

    转:http://technet.microsoft.com/zh-cn/library/cc262995(v=office.14).aspx 本文介绍各个解决方案包,及其在 Microsoft Sh ...

  4. 在User Profile Service中配置AD的同步连接

    转:http://www.360sps.com/Item/ConfigureSynchronizationConnections.aspx 如果要将Active Directory.LDAP 目录和业 ...

  5. HDU 1695 GCD 莫比乌斯反演

    分析:简单的莫比乌斯反演 f[i]为k=i时的答案数 然后就很简单了 #include<iostream> #include<algorithm> #include<se ...

  6. HDU 2682

    思路:由于题目对能相连的点有限制,必须将这些点处理,能相连的点合并到一个集合中,最后查看是否所有点都在一个集合里,若都在说明是一个连通图,存在最小生成树,否则图不连通,不存在最小花费. #includ ...

  7. Ruby应用记录:修改文件中某个字符串

    #修改android客户端中服务器地址的默认值为对应环境的服务器地址 #!/usr/bin/ruby ostr="192.168.88.95:8088" nstr="19 ...

  8. C#中属性简写原理

    1. 属性简写时不能只有get或者set 原因: 如果只有get,那么没有办法给其赋值,所有也就没法get到值: 如果只有set,没有意义,因为根本没法获取到这个值.

  9. 录制屏幕(gif)便于在博客中嵌入软件licecap

  10. nyoj VF函数

    大意就是: 在1到在10的9次方中,找到各个位数和为固定值s的数的个数, 首先我们确定最高位的个数,为1到9: 以后的各位为0,到9: 运用递归的思想,n位数有n-1位数生成 f(n)(s) +=f( ...