Browse Source

Fix invisible showing bug and change animation effect

cooperku_kdanmobile 5 years ago
parent
commit
c12c3c7b5e
1 changed files with 9 additions and 7 deletions
  1. 9 7
      src/main/java/com/kdanmobile/reader/utils/AnimationUtil.kt

+ 9 - 7
src/main/java/com/kdanmobile/reader/utils/AnimationUtil.kt

@@ -349,9 +349,10 @@ class AnimationUtil private constructor() {
         }
 
         fun showViewAlpha(view: View?, duration: Long = 300) {
-            if (view != null && view.visibility != View.VISIBLE) {
-                val pvhA = PropertyValuesHolder.ofFloat("alpha", 0f, 1.0f)
-                val animAlpha = ObjectAnimator.ofPropertyValuesHolder(view, pvhA)
+            if (view != null) {
+                val pvhA = PropertyValuesHolder.ofFloat("alpha", view.alpha, 1.0f)
+                val pvhV = PropertyValuesHolder.ofInt("visibility", view.visibility, View.VISIBLE)
+                val animAlpha = ObjectAnimator.ofPropertyValuesHolder(view, pvhA, pvhV)
                 animAlpha.interpolator = AccelerateInterpolator()
                 animAlpha.addListener(object : AnimatorListenerAdapter() {
                     override fun onAnimationStart(animation: Animator) {
@@ -364,14 +365,15 @@ class AnimationUtil private constructor() {
         }
 
         fun hideViewAlpha(view: View?, duration: Long = 300) {
-            if (view != null && view.visibility == View.VISIBLE) {
-                val pvhA = PropertyValuesHolder.ofFloat("alpha", 1.0f, 0f)
-                val animAlpha = ObjectAnimator.ofPropertyValuesHolder(view, pvhA)
+            if (view != null) {
+                val pvhA = PropertyValuesHolder.ofFloat("alpha", view.alpha, 0f)
+                val pvhV = PropertyValuesHolder.ofInt("visibility", view.visibility, View.INVISIBLE)
+                val animAlpha = ObjectAnimator.ofPropertyValuesHolder(view, pvhA, pvhV)
                 animAlpha.interpolator = AccelerateInterpolator()
                 animAlpha.addListener(object : AnimatorListenerAdapter() {
                     override fun onAnimationEnd(animation: Animator) {
                         super.onAnimationEnd(animation)
-                        Handler(Looper.getMainLooper()).post { view.visibility = View.GONE }
+                        Handler(Looper.getMainLooper()).post { view.visibility = View.INVISIBLE }
                     }
                 })
                 animAlpha.setDuration(duration).start()