---
title: "SWT学习（三）"
author: "mypyg"
date: "2011-05-20T11:33:47Z"
tags: ["Android", "Eclipse"]
categories: ["编程语言"]
slug: "swt"
draft: false
lastmod: "2011-05-20T11:33:47Z"
id: 1051428
url: "https://mypyg.iteye.com/blog/1051428"
---

布局用来控制子控件的位置和大小。
1.FillLayout:
所有的子控件都在一行或者一列，并且大小都一样。
FillLayout fillLayout = new FillLayout();
shell.setLayout(fillLayout);
如果窗口太大，可以shell.pack()使窗口自动变为合适的大小。
竖向：
FillLayout fillLayout = new FillLayout(SWT.VERTICAL);
shell.setLayout(fillLayout);

2.RowLayout
所有的控件都在一行或者一列，但是控件大小可以不一样。

3.GridLayout:
网格布局，每行固定的列数，控件填充完一行，自动换到下一行。

4.FormLayout:
类似于Android下的相对布局，控件可以相对于父窗体或者其他控件来决定位置。


简单Ap使用Eclipse的WindowBuilder插件搭界面就可以了，可视化编辑，非常好用。