728x90
나를 위해 기록하는 Flutter 기초
Alignment로 박스를 배치하는 방법 아홉가지
먼저 나오는 단어는 화면의 세로 방향에 대한 정렬을,
뒤에 나오는 단어는 화면의 가로 방향에 대한 정렬을 나타낸다고 생각하면 쉽다.
Align 위젯을 사용해 Alignment로 박스 배치하기
- center
- centerLeft
- centerRight
- topCenter
- topLeft
- topRight
- bottomCenter
- bottomLeft
- bottomRight
1. center
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Align(
alignment: Alignment.center,
child: Container(
width: 200, height: 200,
color: Colors.amberAccent,
),
),
),
);
}
}
- 가로, 세로 방향 가운데 정렬
2. centerLeft
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Align(
alignment: Alignment.centerLeft,
child: Container(
width: 200, height: 200,
color: Colors.amberAccent,
),
),
),
);
}
}
- 세로 방향 가운데 정렬, 가로 방향 좌측정렬
3. centerRight
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Align(
alignment: Alignment.centerRight,
child: Container(
width: 200, height: 200,
color: Colors.amberAccent,
),
),
),
);
}
}
- 세로 방향 가운데 정렬, 가로 방향 우측정렬
4. topCenter
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Align(
alignment: Alignment.topCenter,
child: Container(
width: 200, height: 200,
color: Colors.amberAccent,
),
),
),
);
}
}
- 세로 방향 위쪽 정렬, 가로 방향 가운데 정렬
5. topLeft
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Align(
alignment: Alignment.topLeft,
child: Container(
width: 200, height: 200,
color: Colors.amberAccent,
),
),
),
);
}
}
- 세로 방향 위쪽정렬, 가로 방향 좌측정렬
6. topRight
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Align(
alignment: Alignment.topRight,
child: Container(
width: 200, height: 200,
color: Colors.amberAccent,
),
),
),
);
}
}
- 세로 방향 위쪽 정렬, 가로 방향 우측정렬
7. bottomCenter
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Align(
alignment: Alignment.bottomCenter,
child: Container(
width: 200, height: 200,
color: Colors.amberAccent,
),
),
),
);
}
}
- 세로 방향 아래쪽정렬, 가로 방향 가운데 정렬
8. bottomLeft
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Align(
alignment: Alignment.bottomLeft,
child: Container(
width: 200, height: 200,
color: Colors.amberAccent,
),
),
),
);
}
}
- 세로 방향 아래쪽정렬, 가로 방향 좌측정렬
9. bottomRight
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Align(
alignment: Alignment.bottomRight,
child: Container(
width: 200, height: 200,
color: Colors.amberAccent,
),
),
),
);
}
}
- 세로 방향 아래쪽정렬, 가로 방향 우측정렬
'Flutter' 카테고리의 다른 글
Flutter BoxDecoration 종류, 사용법 (0) | 2023.07.29 |
---|---|
Flutter 마진(margin), 패딩(padding)으로 여백 만들기 (0) | 2023.07.27 |
Flutter Scaffold로 기초 앱 틀 잡기 연습 (0) | 2023.07.25 |
Flutter 요소 정렬 종류 (0) | 2023.07.23 |
Flutter 가로, 세로 공간 나누기 (0) | 2023.07.21 |