Android 仿Nothing登录页(Kotlin)

Android 仿Nothing登录页(Kotlin)_第1张图片
android.jpg

1、Demo预览

1.gif

2、动画实现

fun showOrHide(isShow: Boolean) {
        isShowing = isShow
        val valueAnimator: ValueAnimator = if (isShow) {
            ValueAnimator.ofInt(0, (getScreenHeight() * 2f / 3f).toInt())
        } else {
            ValueAnimator.ofInt((getScreenHeight() * 2f / 3f).toInt(), 0)
        }
        valueAnimator.addUpdateListener { a ->
            val value = a.animatedValue as Int
            val params = loginBottomLayout.layoutParams
            params.height = value
            loginBottomLayout.layoutParams = params
            Log.d("addUpdateListener", value.toString())
        }
        valueAnimator.duration = 500
        valueAnimator.setTarget(loginBottomLayout)
        valueAnimator.start()
    }

3、下滑关闭

loginBottomLayout.setOnTouchListener(object : View.OnTouchListener {
            var lastX: Float = -1F
            var lastY: Float = -1F
            override fun onTouch(view: View?, event: MotionEvent): Boolean {
                when (event.action) {
                    MotionEvent.ACTION_DOWN -> {
                        lastY = event.y
                        lastX = event.x
                        Log.d("ACTION_DOWN", "x:$lastX,y:$lastY")
                    }
                    MotionEvent.ACTION_UP -> {
                        if (Math.abs(event.x - lastX) < 30 && event.y - lastY > 30) {       //向下滑动逻辑,
                            if (isShowing)
                                showOrHide(false)           //关闭登录或注册
                        }
                        Log.d("ACTION_UP", "x:${event.x},y:${event.y}")
                    }
                }

                return true
            }

        })

4、Demo链接NothingLogin

你可能感兴趣的:(Android 仿Nothing登录页(Kotlin))