ToolBar, DrawerLayout, NavigationView๋ฅผ ๊ตฌํํ๊ธฐ ์ํด ์ด์ฌํ ์์๋ณด๋ ์ค CoordinatorLayout, AppBarLayout, FloatingActionButton์ ๋ํด ์๊ฒ๋์๊ณ , ๊ฐ๊ฐ ์ด๋ค ๊ธฐ๋ฅ์ด ์๋์ง ๊ณต๋ถํ๋ค.
1. CoordinatorLayout
์๋๊ฐ ์๋ ์ ํ๋ฆฌ์ผ์ด์ ์ ๊ตฌ์ฑํ ์ ์๋๋ก ๋์์ฃผ๋ ๊ธฐ๋ณธ Activity ํ ํ๋ฆฟ์ ํฌํจ๋ ๋ ์ด์์์ด๋ค.
๊ทธ๋ ๋ค๋ฉด CoordinatorLayout์ ๋ํ ์ฌ๋ฌ ์ฌ์ค์ ๋ํด ์์๋ณด์.
- FrameLayout์ ๊ธฐ๋ฐ์ ๋ Layout. FrameLayout์ ์์๋ฐ์ ๊ตฌํํ๋ค.
- ์ ํ๋ฆฌ์ผ์ด์ ํ๋ฉด์ ์ต์์ ๋ทฐ๋ก์ ์ฌ์ฉ๋๋ค. (์๋จ์ด ์๋ ์์์์ ์ ์! AppBar ๋๋ FloatingActionButton)
- ์์ ๋ทฐ๋ค๊ณผ์ ์ํธ์์ฉ์ ์ํ ์ปจํ ์ด๋๋ก ์ฌ์ฉ๋๋ค.
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.google.android.material.appbar.AppBarLayout />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Corrdinatorlayout์ ์คํฌ๋กค ์ด๋ฒคํธ์ ๋ฐ๋ผ ์ฑ๋ฐ์ ๋ณํ๋ฅผ ์ค ๋ ํ์ฉํ ์ ์๋ค.
ex) ์คํฌ๋กค์ ์ฑ๋ฐ์ ํฌ๊ธฐ๊ฐ ๋์ด๋๊ฑฐ๋ ์ค์ด๋๋ ํ๋ฉด, ๋ฆฌ์ฌ์ดํด๋ฌ๋ทฐ ๋ฑ์ ์คํฌ๋กคํ ๋ ์๋ก ์คํฌ๋กค์ ์ฑ๋ฐ๊ฐ ์ฌ๋ผ์ง๊ณ ์๋๋ก ์คํฌ๋กค์ ์ฑ๋ฐ๊ฐ ๋ค์ ๋ํ๋๋ ๋ฐ์ํ ํ๋ฉด ๋ฑ
์๋๋ก์ด๋ ๊ณต์ ๊ฐ๋ฐ ๋ฌธ์ : CoordinatorLayout ๊ฐ์ด๋
https://developer.android.com/reference/androidx/coordinatorlayout/widget/CoordinatorLayout
2. AppBarLayout
Android์์ ๊ธฐ๋ณธ์ผ๋ก ์ ๊ณตํ๋ ActionBar ๋๋ Toolbar๋ฅผ ์ด์ฉํ์ฌ ํ๋ฉด ์๋จ์ AppBar๋ฅผ ๊ตฌํํ ๋ ์ฌ์ฉ๋๋ค.
๋จ์ํ Toolbar๋ง ์ฌ์ฉํ์ฌ๋ ๋ฌด๊ดํ์ง๋ง, AppBarLayout์ ์ฌ์ฉํ๋ฉด Activity ์๋จ์ ๋์ฑ ํจ๊ณผ์ ์ผ๋ก ํ์ฉํ ์ ์๋ค.
๊ธฐ๋ณธ์ ์ธ ๊ตฌ์กฐ๋ AppBarLayout ํ๊ทธ ์๋์ Toolbar ํ๊ทธ๋ฅผ ๋ฃ๋๋ค. Toolbar๋ฅผ AppBarLayout์ผ๋ก ๊ฐ์ผ ํํ์ด๋ค.
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeName">
<androidx.appcompat.widget.Toolbar />
</com.google.android.material.appbar.AppBarLayout>
๊ทธ๋ ๋ค๋ฉด Toolbar๋ง ์ฌ์ฉํ์ง ์๊ณ AppBarLayout์ ์ฌ์ฉํ์ ๋์ ์ฅ์ ์ ๋ฌด์์ผ๊น?
- Toolbar, Image, TabLayout ๋ฑ ํ๋ฉด์ ์๋จ์ ๋ ๋๊ฒ ๊ตฌ์ฑํ ์ ์๋ค!
- CoordinatorLayout๊ณผ ํจ๊ป ์ฌ์ฉํ๋ฉด AppBar๋ฅผ ํ๋ํ๊ฑฐ๋ ์ถ์ํ๋ ์ด๋ฒคํธ๋ฅผ ์์ฑํ ์ ์๋ค.
CoordinatorLayout์ ์์ ๋ทฐ์ ์ํธ์์ฉํ์ฌ ์ฌ๋ฌ ์ด๋ฒคํธ ํจ๊ณผ๋ฅผ ๋ณด์ผ ์ ์๋ค. ์ฌ๊ธฐ์ ์์์ผ๋ก AppBarLayout์ ์ฌ์ฉํ๋ฉด ์คํฌ๋กค์ AppBar๊ฐ ๋ํ๋ฌ๋ค๊ฐ, ์ฌ๋ผ์ก๋ค ํ๋ ๋ฑ์ ์ด๋ฒคํธ๋ฅผ ๋ฃ์ ์ ์๋ ๊ฒ์ด๋ค.
AppBarLayout์ LinearLayout์ ์์๋ฐ์ ๊ตฌํ๋์ด ์์ผ๋ฉฐ Vertical ์์ฑ๋ง ์ง์ํ๋ค. ์ฑ๋ฐ์ ํน์ฑ์ ์คํฌ๋กค ์ด๋ฒคํธ๋ฅผ ์ง์ํด์ผํ๋ฉฐ, CoordinatorLayout์ direct child๋ก์ ์ํ ์คํฌ๋กค ์ด๋ฒคํธ์ ๋ฐ์ํ๊ธฐ ์ํจ์ธ ๊ฒ ๊ฐ๋ค.
3. FloatingActionButton
FloatingActionButton(ํ๋กํ ์์ ๋ฒํผ)์ ์ฑ UI์ ๊ธฐ๋ณธ ์์ ์ ํธ๋ฆฌ๊ฑฐํ๋ ์ํ ๋ฒํผ์ด๋ค.
๋ผ๊ณ ์๋๋ก์ด๋ ๊ณต์ ๊ฐ๋ฐ ๋ฌธ์์ ์ ํ์๋๋ฐ ๋ง์ด ๋๋ฌด ์ด๋ ต๋ค. ๋ํํ
๊ทธ๋ฅ ํ๋ฉด ๊ฐ์ฅ ์์ ๋ ์๋ ๋ฒํผ์ธ๊ฑธ.
์ค์ฌ์ FAB๋ผ๊ณ ๋ถ๋ฅด๋ FloatingActionButton์ ๋ ์ด์์ ๋ฌธ์(XML)์ ์ถ๊ฐํ์ฌ ์ฌ์ฉํ ์ ์๋ค.
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginEnd="@dimen/fab_margin"
android:layout_marginBottom="16dp"
app:srcCompat="@android:drawable/ic_dialog_email" />
์์น, ๋ง์ง, ID ๋ฑ์ ์ฌ์ฉ์๊ฐ ์ํ๋๋๋ก ์ปค์คํ ํ์ฌ ์ฌ์ฉํ๋ฉด ๋๋ค. ๋ฒํผ์ ํด๋ฆญํ์ ๋์ ์ด๋ฒคํธ๋ฅผ ์ ์ํ๊ณ ์ถ๋ค๋ฉด Java ์ฝ๋์์ setOnClickListener ํจ์๋ฅผ ๊ตฌํํด์ผ ํ๋ค.
์๋๋ก์ด๋ ๊ณต์ ๊ฐ๋ฐ ๋ฌธ์ : ํ๋กํ ์์ ๋ฒํผ ์ถ๊ฐํ๊ธฐ
https://developer.android.com/guide/topics/ui/floating-action-button?hl=ko
ํ๋กํ ์์ ๋ฒํผ ์ถ๊ฐ | Android ๊ฐ๋ฐ์ | Android Developers
ํ๋กํ ์์ ๋ฒํผ ์ถ๊ฐ ํ๋กํ ์์ ๋ฒํผ(FAB)์ ์ฑ UI์ ๊ธฐ๋ณธ ์์ ์ ํธ๋ฆฌ๊ฑฐํ๋ ์ํ ๋ฒํผ์ ๋๋ค. ์ด ํ์ด์ง์์๋ FAB๋ฅผ ๋ ์ด์์์ ์ถ๊ฐํ๊ณ , ๋ชจ์์ ๋ง์ถค์ค์ ํ๋ฉฐ, ๋ฒํผ ํญ์ ์๋ตํ๋ ๋ฐฉ๋ฒ์
developer.android.com
๋จธํฐ๋ฆฌ์ผ ๋์์ธ ๊ฐ์ด๋๋ผ์ธ : ํ๋กํ ์์ ๋ฒํผ ๋์์ธํ๊ธฐ
https://material.io/components/buttons-floating-action-button#usage
Material Design
Build beautiful, usable products faster. Material Design is an adaptable system—backed by open-source code—that helps teams build high quality digital experiences.
material.io