Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- Java
- Kotlin
- python #circular imports #
- 0xC00000FD
- 파이썬 문법
- 안드로이드 스튜디오
- View.GONE
- 딕셔너리 복사
- cyclic imports
- setVisibility
- 코틀린
- 뷰크기
- 이미지크기
- 1073741571
- 버튼크기
- 자바
Archives
- Today
- Total
개발여행
Kotlin 프래그먼트 전환 애니메이션 효과 본문
우선 res디렉토리에 anim 폴더를 만들고 다음과 같이 xml를 작성한다.
[enter_from_right.xml]
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:fromXDelta="100%" android:toXDelta="0%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="300" />
</set>
[exit_to_right.xml]
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:fromXDelta="0%" android:toXDelta="100%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="300" />
</set>
메인 엑티비티에 다음과 같이 setFrag 함수를 작성한다.
fun setFrag(fragment: Fragment) {
val transaction = supportFragmentManager.beginTransaction()
transaction.setCustomAnimations(R.anim.enter_from_right, 0, 0, R.anim.exit_to_right)
transaction.add(R.id.main_frame, fragment).addToBackStack(null)
//transaction.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_right)
//transaction.add(R.id.main_frame, fragment)
transaction.commit()
}
기존 setFrag 함수에 setCustomAnimations 함수가 추가되었다.
네가지의 인자(enter, exit, popEnter, popExit)가 들어가는데 백스택을 사용하지 않을 경우 popEnter과 popExit 인자는 전달하지 않아도 된다.
그 후 다음과 같이 해당 프래그먼트에서 함수를 사용할 수 있게 해주면 된다.
'Mobile > Kotlin' 카테고리의 다른 글
리사이클러 뷰 사용시 내용이 잘리는 문제 해결 (0) | 2022.06.18 |
---|---|
Kotlin, JAVA 리사이클러 뷰 아이템 숨기기시에 공간이 그대로 남아 있는 현상 (0) | 2022.06.06 |
Kotlin 이전 프래그먼트로 돌아가기 & 뒤로가기 두번 눌러서 앱종료하기 (0) | 2022.05.15 |
Kotlin 프래그먼트 전환시 데이터 전달 (0) | 2022.05.15 |
Kotlin 프래그먼트 전환 (0) | 2022.05.15 |