728x90
반응형
SMALL
일단 코드 저장
class ToggleAnimUtil {
companion object {
fun toggleArrow(view: View, isExpanded: Boolean): Boolean {
if (isExpanded) {
view.animate().setDuration(200).rotation(180f)
return true
} else {
view.animate().setDuration(200).rotation(0f)
return false
}
}
fun expand(view: View) {
val animation = expandAction(view)
view.startAnimation(animation)
}
private fun expandAction(view: View) : Animation {
view.measure(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
val actualHeight = view.measuredHeight
view.layoutParams.height = 0
view.visibility = View.VISIBLE
val animation = object : Animation() {
override fun applyTransformation(interpolatedTime: Float, t: Transformation?) {
view.layoutParams.height = if (interpolatedTime == 1f) ViewGroup.LayoutParams.WRAP_CONTENT
else (actualHeight * interpolatedTime).toInt()
view.requestLayout()
}
}
animation.duration = (actualHeight / view.context.resources.displayMetrics.density).toLong()
view.startAnimation(animation)
return animation
}
fun collapse(view: View) {
val actualHeight = view.measuredHeight
val animation = object : Animation() {
override fun applyTransformation(interpolatedTime: Float, t: Transformation?) {
if (interpolatedTime == 1f) {
view.visibility = View.GONE
} else {
view.layoutParams.height = (actualHeight - (actualHeight * interpolatedTime)).toInt()
view.requestLayout()
}
}
}
animation.duration = (actualHeight / view.context.resources.displayMetrics.density).toLong()
view.startAnimation(animation)
}
}
}
'Android Study' 카테고리의 다른 글
Android Statusbar 설정 방법(색상, 이미지, 투명) (0) | 2024.02.19 |
---|---|
Google Develop Console 이유없는 업로드 안됨현상 (0) | 2023.11.07 |
Android Default Splash Disable ( api > 12 ) (1) | 2023.10.24 |
안드로이드 스튜디오 LogCat 이전버전으로 돌리기 (0) | 2023.10.17 |
동적 변경 뷰 만들기(constrainlayout, chainStyle, bias) (1) | 2023.10.17 |