Android 自学之线性布局 LinearLayout
线性布局(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的更多相关文章
- .Net程序猿玩转Android开发---(6)线性布局LinearLayout
LinearLayout控件是Android中重要的布局控件,是一个线性控件,所谓线性控件的意思是指该控件里面的内容仅仅能水平或垂直排列.也就 ...
- Android学习笔记(11):线性布局LinearLayout
线性布局LinearLayout是指在横向或是竖向一个接一个地排列.当排列的组件超出屏幕后,超出的组件将不会再显示出来. LinearLayout支持的XML属性和相应方法如表所看到的: Attrib ...
- 安卓开发06:布局-线性布局 LinearLayout
LinearLayout把视图组织成一行或一列.子视图能被安排成垂直的或水平的.线性布局是非常常用的一种布局方式. 请看一个布局例子: <LinearLayout xmlns:android=& ...
- 线性布局(LinearLayout)
线性布局(LinearLayout) 备注 match_parent填充布局单元内尽可能多的空间 wrap_content完整显示控件内容 orientation有两个值,horizontal水平显示 ...
- Android——布局(线性布局linearLayout,表格布局TableLayout,帧布局FrameLayout)
线性布局: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:androi ...
- Android布局之线性布局——LinearLayout
本文将详细介绍线性布局的各种xml属性. xml属性 <?xml version="1.0" encoding="utf-8"?> <Line ...
- Android 线性布局 LinearLayout
垂直布局 vertical <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" ...
- 线性布局LinearLayout
常用属性 id:控件唯一属性 android:id="@+id/ll_1" --------------------------------------- layout_width ...
- Android开发之线性布局详解(布局权重)
布局权重 线性布局支持给个别的子视图设定权重,通过android:layout_weight属性.就一个视图在屏幕上占多大的空间而言,这个属性给其设 定了一个重要的值.一个大的权重值,允许它扩大到填充 ...
随机推荐
- Oracle并行更新的两种方式(merge/update内联视图)
对于Oracle的两表联合更新的场景(有A.B两表,以A.id=B.id关联,根据B表中的记录更新A表中的相应字段),一般有update内联视图和merge两种方式,下面举例介绍: 创建用例表: ...
- hadoop的wordcount例子运行
可以通过一个简单的例子来说明MapReduce到底是什么: 我们要统计一个大文件中的各个单词出现的次数.由于文件太大.我们把这个文件切分成如果小文件,然后安排多个人去统计.这个过程就是”Map”.然后 ...
- BZOJ_3207_花神的嘲讽计划1_(Hash+主席树)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=3207 给出一个长度为\(n\)的串,以及\(m\)个长度为\(k\)的串,求每个长度为\(k\ ...
- backup archivelog all
OLTP系统的生产库一般都是打开归档模式,当CUD操作频繁并且时常使用大批量处理时,每天的归档日志也是超级大的,如果长期保留这些归档日志磁盘空间消耗是很恐怖的,所以我们在使用RMAN进行数据库备份时 ...
- win7无法识别U盘,驱动信息:该设备的驱动程序未被安装。 (代码 28)
台式机的win7 64位系统可以识别u盘,但笔记本的win7 64位却识别不了,说明U盘是可以用的.查看笔记本的设备管理器,发现驱动安装失败,提示信息为“该设备的驱动程序未被安装. (代码 28) ” ...
- 打印grid
void PrintButtonClick(object sender, EventArgs e) { PrintPreviewDialog dlg = new PrintPreviewDialog( ...
- Asm Shader Reference --- Shader Model 2.0 part
ps部分 ps_2_0 概览 Instruction Set Name Description Instruction slot ...
- 多线程归并排序(摘自githhub)
package com.rationalcoding.sort; import java.util.ArrayList; import java.util.Arrays; import java.ut ...
- Linux设备驱动中的异步通知与异步I/O
异步通知概念: 异步通知的意识是,一旦设备就绪,则主动通知应用程序,这样应用程序根本就不需要查询设备状态,这一点非常类似于硬件上的“中断”概念,比较准确的称谓是“信号驱动的异步IO”,信号是在软件层次 ...
- HW4.33
public class Solution { public static void main(String[] args) { int sum; for(int i = 6; i < 1000 ...