๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ“ฑ Cross Platform/Flutter

[Flutter] Flutter ๋ ˆ์ด์•„์›ƒ ์‰ฝ๊ฒŒ ์ดํ•ดํ•˜๊ธฐ - 1 (feat. Column,Row,MainAxisAlignment,CrossAlignment)

by Fomagran ๐Ÿ’ป 2021. 12. 11.
728x90
๋ฐ˜์‘ํ˜•

์•ˆ๋…•ํ•˜์„ธ์š” Foma ๐Ÿ’ป ์ž…๋‹ˆ๋‹ค!

 

์ •๋ง ์˜ค๋žœ๋งŒ์— Flutter๋ฅผ ๋‹ค์‹œ ๊ณต๋ถ€ํ•˜๋Š”๋ฐ.. ๋ ˆ์ด์•„์›ƒ ํ•˜๋Š” ๋ฐฉ๋ฒ•์ด iOS์™€๋Š” ๋‹ฌ๋ผ์„œ.. ํ—ท๊ฐˆ๋ฆฌ๋”๋ผ๊ตฌ์š”.

 

๊ทธ๋ž˜์„œ ๋ ˆ์ด์•„์›ƒ ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์‰ฝ๊ฒŒ ์ดํ•ดํ•˜๊ธฐ ์œ„ํ•ด์„œ ๊ธ€์„ ์ •๋ฆฌํ•ด๋ณด๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค!

 

๋ฐ”๋กœ ์‹œ์ž‘ํ• ๊ฒŒ์š”~


Column

 

๋จผ์ € ์ปฌ๋Ÿผ ์œ„์ ฏ๋ถ€ํ„ฐ ๋‹ค๋ค„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

 

์ปฌ๋Ÿผ์€ "ํ–‰"์„ ๋œปํ•˜์ฃ ? ์ฆ‰, ์„ธ๋กœ๋กœ ์œ„์ ฏ๋“ค์„ ๋ฐฐ์น˜ํ•˜๊ณ  ์‹ถ์„ ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ์œ„์ ฏ์ž…๋‹ˆ๋‹ค.

 

์•„๋ž˜์™€ ๊ฐ™์ด ์•„๋ฌด๋Ÿฐ ์˜ต์…˜์„ ์ฃผ์ง€ ์•Š์œผ๋ฉด ์™ผ์ชฝ ์ƒ๋‹จ์— ๋ฐฐ์น˜๋˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

 

Column(children: <Widget>[CircleAvatar(radius: 50.0)])

 

 

์ปฌ๋Ÿผ ์•ˆ์— ์—ฌ๋Ÿฌ ๊ฐœ์˜ ์œ„์ ฏ์„ ๋„ฃ์œผ๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด ์„ธ๋กœ๋กœ ๋ฐฐ์น˜๋˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

 

Column(children: <Widget>[CircleAvatar(radius: 50.0),
			  CircleAvatar(radius: 50.0),
                          CircleAvatar(radius: 50.0)])

 

 

์œ„์ ฏ๋“ค์ด ๋„ˆ๋ฌด ๋ถ™์–ด์žˆ๋Š” ๊ฒƒ ๊ฐ™์ฃ ? ์‚ฌ์ด์— ๊ณต๊ฐ„์„ ๋‘๊ณ ์‹ถ๋‹ค๋ฉด ์—ฌ๋Ÿฌ๊ฐ€์ง€ ๋ฐฉ๋ฒ•์ด ์žˆ๋Š”๋ฐ์š”.

 

Column(children: <Widget>[
          CircleAvatar(radius: 50.0),
          SizedBox(height: 10),
          CircleAvatar(radius: 50.0),
          SizedBox(height: 10),
          CircleAvatar(radius: 50.0)
        ],
      )

 

1. ์œ„์ ฏ ์‚ฌ์ด์— SizeBox๋ฅผ ๋‘ฌ์„œ ์—ฌ๋ฐฑ์„ ๋งŒ๋“ ๋‹ค.

 

์ด ๋ฐฉ๋ฒ•์€ ์œ„์ ฏ๋งˆ๋‹ค ์‚ฌ์ด์ฆˆ๋ฐ•์Šค๋ฅผ ๋‘ฌ์•ผํ•˜๋‹ˆ ๋ฒˆ๊ฑฐ๋กญ๊ณ  ๋ณ„๋กœ ์ถ”์ฒœํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค...

 

 

2. Column์„ Container๋กœ ๊ฐ์‹ธ๊ณ  ๊ท ๋“ฑํ•˜๊ฒŒ ๋ฐฐ์น˜ํ•œ๋‹ค.

 

์ปฌ๋Ÿผ์— ํŠน์ • ๋†’์ด๋ฅผ ์ง€์ •ํ•  ์ˆ˜ ์—†์œผ๋ฏ€๋กœ ์ปจํ…Œ์ด๋„ˆ๋กœ ๊ฐ์‹ผ ๋‹ค์Œ height๋ฅผ ์ง€์ •ํ•ด์ค๋‹ˆ๋‹ค.

 

๊ทธ๋ฆฌ๊ณ  mainAxisAlignment์˜ .spaceEvenly(๊ท ๋“ฑํ•˜๊ฒŒ ์—ฌ๋ฐฑ์„ ์คŒ)์„ ์ง€์ •ํ•ด ์ค๋‹ˆ๋‹ค.

 

Container(
        height: 400,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          children: <Widget>[
            CircleAvatar(radius: 50.0),
            CircleAvatar(radius: 50.0),
            CircleAvatar(radius: 50.0)
          ],
        )

 


Row

 

๋กœ์šฐ ์œ„์ ฏ์€ ์ปฌ๋Ÿผ ์œ„์ ฏ๊ณผ ๋ฐ˜๋Œ€๋กœ "์—ด"์„ ๋œปํ•ฉ๋‹ˆ๋‹ค.

 

๊ณ ๋กœ ์œ„์ ฏ๋“ค์„ ๊ฐ€๋กœ๋กœ ๋ฐฐ์น˜ํ•˜๊ณ  ์‹ถ์„ ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ์œ„์ ฏ์ž…๋‹ˆ๋‹ค.

 

Row(children: <Widget>[
                CircleAvatar(radius: 50.0),
                CircleAvatar(radius: 50.0),
                CircleAvatar(radius: 50.0)
              ]
            )

 

 

Row์— ์—ฌ๋ฐฑ์„ ์ฃผ๋Š” ๋ฐฉ๋ฒ•์€ ์ปฌ๋Ÿผ๊ณผ ๋™์ผํ•˜๋‹ˆ ์Šคํ‚ตํ•˜๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.


MainAxisAlignment

 

์œ„์—์„œ ๊ท ๋“ฑํ•˜๊ฒŒ ๋ถ„๋ฐฐํ•  ๋•Œ MainAxisAlignment๋ฅผ ์ง€์ •ํ•ด์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค.

 

๊ทธ๋ ‡๋‹ค๋ฉด MainAxisAlignment๋Š” ๋ฌด์—‡์ผ๊นŒ์š”?

 

์ด๊ฒƒ์€ ์œ„์ ฏ์˜ ์ฃผ์ถ•์„ ์ •ํ•ด์ฃผ๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

 

์ปฌ๋Ÿผ์€ ์ฃผ์ถ•์ด ์„ธ๋กœ์ด๊ณ , ์—ด์„ ์ฃผ์ถ•์ด ๊ฐ€๋กœ์ž…๋‹ˆ๋‹ค.

 

์ถœ์ฒ˜: ํ”Œ๋Ÿฌํ„ฐ ๊ณต์‹ ๋ฌธ์„œ

 

MainAxisAlignment์˜ ์˜ต์…˜์€ ์ด 6๊ฐ€์ง€๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

 

start,center,end,spaceAround,spaceBetween,spaceEvenly์ด๋ ‡๊ฒŒ 6๊ฐ€์ง€๊ฐ€ ์žˆ๋Š”๋ฐ์š”.

 

ํ•˜๋‚˜์”ฉ ์‚ดํŽด๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

 

 

1. start

 

.start๋ฅผ ์ง€์ •ํ•ด์ฃผ๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด ์ปฌ๋Ÿผ์˜ ์ฃผ์ถ•(์„ธ๋กœ)์ด 0์œผ๋กœ ๋˜์–ด ๊ฐ€์žฅ ์œ—์ชฝ์— ๋ฐฐ์น˜๋˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

 

2. center

 

.center๋ฅผ ์ง€์ •ํ•ด์ฃผ๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด ์ปฌ๋Ÿผ์˜ ์ฃผ์ถ•(์„ธ๋กœ)์ด ์ค‘์•™์œผ๋กœ ๋˜์–ด ๊ฐ€์šด๋ฐ์— ๋ฐฐ์น˜๋˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

 

 

3. end

 

.end๋ฅผ ์ง€์ •ํ•ด์ฃผ๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด ์ปฌ๋Ÿผ์˜ ์ฃผ์ถ•(์„ธ๋กœ)์ด ๋์œผ๋กœ ๋˜์–ด ๊ฐ€์žฅ ์•„๋žซ์ชฝ์— ๋ฐฐ์น˜๋˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

 

 

4. spaceAround

 

์œ„์ ฏ์ด ๊ท ๋“ฑํ•˜๊ฒŒ ๋ฐฐ์น˜๋˜๊ณ  ์œ„์™€ ์•„๋ž˜์— ์œ„์ ฏ ๊ฐ„์˜ ๊ฑฐ๋ฆฌ์˜ ์ ˆ๋ฐ˜๋งŒํผ ์—ฌ๋ฐฑ์ด ์ƒ๊น๋‹ˆ๋‹ค.

 

 

5. spaceEvenly

 

์œ„์ ฏ์ด ๊ท ๋“ฑํ•˜๊ฒŒ ๋ฐฐ์น˜๋˜๊ณ  ๊ทธ ์—ฌ๋ฐฑ๋งŒํผ ์œ„์™€ ์•„๋ž˜์— ์—ฌ๋ฐฑ์ด ์ƒ๊น๋‹ˆ๋‹ค.

 

 

6. spaceBetween

 

์œ„์ ฏ์ด ๊ท ๋“ฑํ•˜๊ฒŒ ๋ถ„๋ฐฐ๋˜๊ณ  ์œ„์™€ ์•„๋ž˜์— ์—ฌ๋ฐฑ์ด ์ƒ๊ธฐ์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

 


 

CrossAxisAlignment

 

์ด์   MainAxisAlignment์˜ ๊ต์ฐจ ๋ฐฉํ–ฅ์ธ CrossAxisAlignment๋ฅผ ๋‹ค๋ค„๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

 

CrossAxisAlignment์˜ ์˜ต์…˜์€ ์ด 5๊ฐ€์ง€๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

 

start,center,end,baseline,stretch ์ด๋ ‡๊ฒŒ 5๊ฐ€์ง€๊ฐ€ ์žˆ๋Š”๋ฐ์š”.

 

ํ•˜๋‚˜์”ฉ ์‚ดํŽด๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

 

 

1. start

 

.start๋ฅผ ์ง€์ •ํ•ด์ฃผ๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด ๊ฐ€๋กœ๊ฐ€ 0์ด ๋˜์–ด ๊ฐ€์žฅ ์™ผ์ชฝ์— ๋ฐฐ์น˜๋˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

 

 

2. center

 

.center๋ฅผ ์ง€์ •ํ•ด์ฃผ๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด ๊ฐ€๋กœ๊ฐ€ ์ค‘์•™์ด ๋˜์–ด ๊ฐ€์šด๋ฐ์— ๋ฐฐ์น˜๋˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

 

(์ปฌ๋Ÿผ์€ ๊ธฐ๋ณธ์ ์œผ๋กœ width๊ฐ€ ๊ฐ์‹ธ์—ฌ์ ธ ์žˆ๋Š” ๊ฐ€๋กœ๋กœ ๋˜๊ธฐ ๋•Œ๋ฌธ์— Container๋กœ ๊ฐ€๋กœ๋ฅผ ๋ฌดํ•œ๋Œ€๋กœ ๊ฐ์‹ธ๊ณ  ํ™•์ธํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.)

 

Container(
              width: double.infinity,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: <Widget>[
                  CircleAvatar(radius: 50.0),
                  CircleAvatar(radius: 50.0),
                  CircleAvatar(radius: 50.0),
                ],
              ),
            )

 

 

3. end

 

.end๋ฅผ ์ง€์ •ํ•ด์ฃผ๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด ๊ฐ€๋กœ๊ฐ€ ๋์ด ๋˜์–ด ๊ฐ€์žฅ ์˜ค๋ฅธ์ชฝ์— ๋ฐฐ์น˜๋˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

 

 

4. stretch

 

.stretch๋ฅผ ์ง€์ •ํ•ด์ฃผ๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด ๊ฐ€๋กœ๊ฐ€ ์‹œ์ž‘๋ถ€ํ„ฐ ๋๊นŒ์ง€ ํ™•์žฅ๋˜์–ด .center๋ž‘ ๋น„์Šทํ•˜๊ฒŒ ๋ณด์ด๋Š”๋ฐ์š”.

 

 

์ปจํ…Œ์ด๋„ˆ์— ๊ฐ€๋กœ์™€ ์„ธ๋กœ๊ฐ’์„ ์ง€์ •ํ•˜๊ณ  ํ™•์ธํ•ด๋ณด๋ฉด ์ปจํ…Œ์ด๋„ˆ์˜ ๊ฐ€๋กœ๊ฐ’์ด ๋ฌด์‹œ๋œ ์ฑ„๋กœ ํ™•์žฅ๋˜๋Š” ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

Container(
              width: double.infinity,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.stretch,
                children: <Widget>[
                  Container(width: 50,height: 50,color: Colors.amber),
                  Container(width: 50, height: 50, color: Colors.blueAccent),
                  Container(width: 50, height: 50, color: Colors.greenAccent)
                ],
              ),
            )

 

 

 

5. baseline

 

.baseline์„ ์ง€์ •ํ•ด์ฃผ๊ฒŒ ๋˜๋ฉด ์•„๋ž˜์™€ ๊ฐ™์€ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค.

 

ํ…์ŠคํŠธ ๋ฒ ์ด์Šค๋ผ์ธ์ด ๋ฐ˜๋“œ์‹œ ์š”๊ตฌ๋œ๋‹ค๊ณ  ์•Œ๋ ค์ฃผ๋Š”๋ฐ์š”.

 

 

์•„๋ž˜์™€ ๊ฐ™์ด ๋ฐ˜๋“œ์‹œ TextBaseline๋„ ์ง€์ •ํ•ด์ค˜์•ผ ํ•ฉ๋‹ˆ๋‹ค.

 

Column(
                crossAxisAlignment: CrossAxisAlignment.baseline,
                textBaseline: TextBaseline.alphabetic,
                children: <Widget>[
                  Text(
                    "Fomagran ์•ˆ์˜ํ›ˆ",
                    style: TextStyle(fontSize: 30, color: Colors.white),
                  ),
                  Text(
                    "Fomagran ์•ˆ์˜ํ›ˆ",
                    style: TextStyle(fontSize: 30, color: Colors.white),
                  ),
                  Text(
                    "Fomagran ์•ˆ์˜ํ›ˆ",
                    style: TextStyle(fontSize: 30, color: Colors.white),
                  ),
                ],
              )

 

 

์ง€์ •ํ•ด์ค€ ๊ธ€์ž์˜ ๊ธฐ์ค€์„ ์— ๋งž๊ฒŒ ๋ฐฐ์น˜๋ฉ๋‹ˆ๋‹ค.

 

 


TextBaseline

 

๊ทธ๋ ‡๋‹ค๋ฉด TextBaseline์€ ๋ฌด์—‡์ผ๊นŒ์š”?

 

์•„๋ž˜์™€ ๊ฐ™์ด alphabetic,ideographic ๋‘๊ฐ€์ง€ ์˜ต์…˜์ด ์กด์žฌํ•ฉ๋‹ˆ๋‹ค.

 

 

1. alphabetic

 

.alphabetic์€ ์˜์–ด์˜ ์•„๋ž˜ ๊ธฐ์ค€์œผ๋กœ ์ •๋ ฌ๋ฉ๋‹ˆ๋‹ค.

 

 

2. ideographic

 

.ideographic์€ ์˜์–ด๊ฐ€ ์•„๋‹Œ ๋ฌธ์ž์˜ ์•„๋ž˜ ๊ธฐ์ค€์œผ๋กœ ์ •๋ ฌ๋ฉ๋‹ˆ๋‹ค.


Reference

 

 

Flutter ๋ ˆ์ด์•„์›ƒ

Flutter ๋ ˆ์ด์•„์›ƒ์˜ ๋ฉ”์ปค๋‹ˆ์ฆ˜๊ณผ ๋ ˆ์ด์•„์›ƒ์„ ๋งŒ๋“œ๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ๋ฐฐ์›Œ๋ด…์‹œ๋‹ค.

flutter-ko.dev

 

728x90
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€