#1 ํ๋๊ทธ๋จผํธ ์ ํ ์ ๋๋ฉ์ด์ ์ ์ ์ฉํ ์ํ ์ฑ
[Android] Navigation - ๊ธฐ์ด
#1 ์ด์ ๊ธ [Android] Navigation - ํ๊ฒฝ ์ค์ #1 Navigation#1-1 ์กํฐ๋นํฐ ๋ฐ ํ๋๊ทธ๋จผํธ ๊ตฌ์ฑ์ ํธ๋ ๋์์ฆ ์๋๋ก์ด๋ ๊ฐ๋ฐ์ ํธ๋ ๋๋ ํ๋์ ์กํฐ๋นํฐ, ์ฌ๋ฌ ๊ฐ์ ํ๋๊ทธ๋จผํธ๋ค. ์ด๋ ๊ตฌ๊ธ์ ๊ถ์ฅ์ฌํญ
kenel.tistory.com
์ ๊ฒ์๊ธ์ ์์ฑ๋ ์ฑ์ ์์ ํด ํ๋๊ทธ๋จผํธ ์ ํ ์ ์ ๋๋ฉ์ด์ ์ ์ ์ฉํด๋ณธ๋ค.
#2 ํ๋๊ทธ๋จผํธ ์ ํ ์ ๋๋ฉ์ด์
#2-1 Action์ ์์ฑ

Navigation graph๋ฅผ Design ๋ชจ๋๋ก ์ฐ๋ค. ๊ทธ๋ฆฌ๊ณ Action์ ํด๋ฆญํ๋ฉด Animation์ด๋ผ๋ ์์ฑ์ ๊ฐ์ง๊ณ ์์์ด ๋ณด์ธ๋ค. ์ฆ, ํ๋๊ทธ๋จผํธ์ ์ ํ ์ ๋๋ฉ์ด์ ์ Action์ด ๊ด๋ฆฌํ๋ค๋ ์๊ธฐ๋ค. ์ด 4๊ฐ์ ์์ฑ์ด ์์ผ๋ฉฐ ๊ฐ๊ฐ์ ๋์ ์๊ธฐ๋ ๋ค์๊ณผ ๊ฐ๋ค.
#2-2 enterAnim
๋ค๋ฅธ ๋ชฉ์ ์ง ํ๋๊ทธ๋จผํธ๊ฐ ์ข ๋ฃ๋๋ฉฐ ํ์ฌ ํ๋๊ทธ๋จผํธ๋ก ์ ํํ์ ๋ ๋์ค๋ ์ ๋๋ฉ์ด์ .
#2-3 exitAnim
ํ์ฌ ํ๋๊ทธ๋จผํธ๊ฐ ์ข ๋ฃ๋ ๋ ๋ค๋ฅธ ํ๋๊ทธ๋จผํธ๋ก ์ ํ๋๋ฉฐ ๋์ค๋ ์ ๋๋ฉ์ด์ .
#2-4 popEnterAnim
(์ฌ์ฉ์์ ๋ค๋ก๊ฐ๊ธฐ ๋ฒํผ ํด๋ฆญ์ผ๋ก ์ธํด) ์ด์ ๋ชฉ์ ์ง ํ๋๊ทธ๋จผํธ๊ฐ ์ข ๋ฃ๋๋ฉฐ ํ์ฌ ํ๋๊ทธ๋จผํธ๋ก ์ ํํ์ ๋ ๋์ค๋ ์ ๋๋ฉ์ด์ .
#2-5 popExitAnim
(์ฌ์ฉ์์ ๋ค๋ก๊ฐ๊ธฐ ๋ฒํผ ํด๋ฆญ์ผ๋ก ์ธํด) ํ์ฌ ํ๋๊ทธ๋จผํธ๊ฐ ์ข ๋ฃ๋ ๋ ๋ค๋ฅธ ํ๋๊ทธ๋จผํธ๋ก ์ ํ๋๋ฉฐ ๋์ค๋ ์ ๋๋ฉ์ด์ .
#3 ์ ๋๋ฉ์ด์ ํ์ผ ์์ฑ
#3-1 ๊ฐ์ ธ์ฌ ์ ๋๋ฉ์ด์ XML ๋ฆฌ์์ค ํ์ผ
Android Left to Right slide animation
I have three activities whose launch modes are single instance. Using onfling(), I swing them left and right. The problem is when I swipe right to left the slide transition is okay but when I swipe
stackoverflow.com
์ด ์คํ์ค๋ฒํ๋ก์ฐ ์ฌ์ดํธ์์ ์ ๋๋ฉ์ด์ ๋ฆฌ์์ค ํ์ผ๋ค์ ๊ฐ์ ธ์จ๋ค.
#3-2 ์ ๋๋ฉ์ด์ XML ๋ฆฌ์์ค ํ์ผ ๊ฐ์ ธ์ค๊ธฐ

๋ชจ๋์ ์ด๋ฆ(์ฌ๊ธฐ์๋ "app")์ ์ฐํด๋ฆญํ๋ฉด ๋์ค๋ ๋ฉ๋ด์์ [New] - [Android Resource File]์ ํด๋ฆญํ๋ค.

์ด๋ฆ์๋ anim_slide_in_left์ ๊ฐ์ด ์คํ์ค๋ฒํ๋ก์ฐ ์ฌ์ดํธ์ ์๋ ํ์ผ์ ์ด๋ฆ์ ๊ทธ๋๋ก ๋ณต์ฌํด ๋ถ์ฌ๋ฃ๋๋ค. Resource type์ Animation์ผ๋ก ์ค์ ํ๊ณ , OK ๋ฒํผ์ ๋๋ฅธ๋ค.
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="600"
android:fromXDelta="100%"
android:toXDelta="0%" >
</translate>
</set>
๋ง๋ค์ด์ง ํ์ผ์ ๋ด์ฉ ๋ํ ์์ ๊ฐ์ด ๊ทธ๋๋ก ๋ณต์ฌํด ๋ถ์ฌ๋ฃ๋๋ค. ์ฐธ๊ณ ๋ก, <translate> ํ๊ทธ์ android:duration ์์ฑ์ ์ ๋๋ฉ์ด์ ์ ์๊ฐ์ ์๋ฏธํ๋ค. ์ ๋๋ฉ์ด์ ์ ๋น ๋ฅด๊ฒ ํ๊ณ ์ถ๋ค๋ฉด ๋ฎ์ ๊ฐ์, ๋๋ฆฌ๊ฒ ํ๊ณ ์ถ๋ค๋ฉด ๋์ ๊ฐ์ ํ ๋นํ๋ค.
anim_slide_in_left ์ธ์ ๋๋จธ์ง ๋ค๋ฅธ ์ ๋๋ฉ์ด์ XML ๋ฆฌ์์ค ํ์ผ๋ค๋ ๊ฐ์ ๋ฐฉ์์ผ๋ก ๊ฐ์ ธ์จ๋ค.
#4 ์ ๋๋ฉ์ด์ ์ฌ์ฉํ๊ธฐ
#4-1 Design ๋ชจ๋์์ ์ค์ ํ๊ธฐ

Action์ 4๊ฐ์ง Animation ์์ฑ ์ ์ ํ ์ ๋๋ฉ์ด์ ์ ๋ฃ์ด์ค๋ค.
#4-2 Code ๋ชจ๋์์ ์ค์ ํ๊ธฐ
<?xml version="1.0" encoding="utf-8"?>
<navigation 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:id="@+id/nav_graph"
app:startDestination="@id/homeFragment">
<fragment
android:id="@+id/homeFragment"
android:name="com.example.applyanimation.HomeFragment"
android:label="fragment_home"
tools:layout="@layout/fragment_home">
<action
android:id="@+id/action_homeFragment_to_secondFragment"
app:destination="@id/secondFragment"
app:enterAnim="@anim/anim_slide_in_left"
app:exitAnim="@anim/anim_slide_in_right"
app:popEnterAnim="@anim/anim_slide_out_left"
app:popExitAnim="@anim/anim_slide_out_right" />
</fragment>
<fragment
android:id="@+id/secondFragment"
android:name="com.example.applyanimation.SecondFragment"
android:label="fragment_second"
tools:layout="@layout/fragment_second" />
</navigation>
Code ๋ชจ๋์์ ์์ ๊ฐ์ด ์ค์ ํ๋ค.
#5 ์์ฝ
ํ๋๊ทธ๋จผํธ ์ ํ ์ ๋๋ฉ์ด์ ์ Action์ด ๊ด๋ฆฌํ๋ค.
#6 ์์ฑ๋ ์ฑ
android-practice/navigation/ApplyAnimation at master ยท Kanmanemone/android-practice
Contribute to Kanmanemone/android-practice development by creating an account on GitHub.
github.com
'๊นจ์ ๊ฐ๋ ๐ > Android' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Android] RecyclerView - Adapter์ ์ธ์(Argument) ์ ๋ฌ (0) | 2024.02.03 |
---|---|
[Android] RecyclerView - ๊ธฐ์ด (0) | 2024.02.02 |
[Android] Navigation - ๊ธฐ์ด (0) | 2024.01.26 |
[Android] Navigation - ํ๊ฒฝ ์ค์ (0) | 2024.01.25 |
[Android] Fragment์ ์๋ช ์ฃผ๊ธฐ (0) | 2024.01.24 |