From 77b8d23940befe1a0d6c090e7076d34aa5b0b598 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Thu, 26 May 2022 12:22:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=90=AF=E5=8A=A8=E6=97=B6?= =?UTF-8?q?=E4=BC=9A=E9=97=AA=E4=B8=80=E4=B8=8B=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 +-- .../java/com/yutou/popdialog/POPDialog.kt | 35 ++++++++++++++++--- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 6f6d9f7..6cab56e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ *.iml .gradle /local.properties -/.idea +/.idea/ /.idea/caches /.idea/libraries /.idea/modules.xml @@ -12,4 +12,4 @@ /build /captures .externalNativeBuild -.cxx +.cxx \ No newline at end of file diff --git a/POPDialog/src/main/java/com/yutou/popdialog/POPDialog.kt b/POPDialog/src/main/java/com/yutou/popdialog/POPDialog.kt index 2f22b83..2b36aff 100644 --- a/POPDialog/src/main/java/com/yutou/popdialog/POPDialog.kt +++ b/POPDialog/src/main/java/com/yutou/popdialog/POPDialog.kt @@ -1,5 +1,6 @@ package com.yutou.popdialog +import android.animation.Animator import android.animation.ObjectAnimator import android.annotation.SuppressLint import android.app.Activity @@ -64,6 +65,7 @@ class POPDialog : Dialog { ) windowParams.gravity = Gravity.BOTTOM view.layoutParams = windowParams + view.y=+POPDialogUtils.getDisplay(activityContext).mode.physicalHeight.toFloat() mainView.addView(view) super.setContentView(mainView) } @@ -174,16 +176,35 @@ class POPDialog : Dialog { * @param expansion true 展开 false 拉下 */ private fun expansion(expansion: Boolean) { + if (showModel == 0 && !expansion) { + finish() + return + } val viewAnim = if (expansion) { ObjectAnimator.ofFloat(view, "translationY", 0f).setDuration(300L) } else { ObjectAnimator.ofFloat(view, "translationY", expansionY).setDuration(300L) } - showModel = if (expansion) { - 1 - } else { - 0 - } + + viewAnim.addListener(object : Animator.AnimatorListener { + override fun onAnimationStart(p0: Animator?) { + } + + override fun onAnimationEnd(p0: Animator?) { + showModel = if (expansion) { + 1 + } else { + 0 + } + } + + override fun onAnimationCancel(p0: Animator?) { + } + + override fun onAnimationRepeat(p0: Animator?) { + } + + }) viewAnim.start() } @@ -267,6 +288,10 @@ class POPDialog : Dialog { view.startAnimation(animation) } + override fun onTouchEvent(event: MotionEvent): Boolean { + return touch.onTouchEvent(event) + } + /** * 触摸事件 */