近段时间的学习碎片整理(25)

一、使用Glide加载图片时,图片裁剪为圆角

//glide 圆角设置 
val options = RequestOptions()
    .optionalTransform(CircleCrop())
    .transform(RoundedCorners(dip(20)))
    .placeholder(R.mipmap.img_desk_voice_bg)
Glide
    .with(this)
    .load(picturePath)
    .apply(options)
    .into(binding.ivBackground)

二、简单的弹出动画

        1、在res下创建anim文件夹,弹出及消失动画xml文件如下:

                dialog_in.xml



    
    
    

    
    
    

    

        dialog_out.xml:



    
    
    

    
    
    

        2、使用动画效果时,对应的view的visibility需要为可见状态

 /**
     * 对话框出现/消失 动画
     * @param view View
     * @param anim Int
     */
    private fun animationInOrOut(view: View, anim: Int) {
        val animation =
            AnimationUtils.loadAnimation(this@FocusModeActivity, anim).also {
                it.duration = 500
                it.fillAfter = true
                it.setAnimationListener(object : Animation.AnimationListener{
                    override fun onAnimationStart(animation: Animation?) {
                    }

                    override fun onAnimationEnd(animation: Animation?) {
                        //需要清除动画
                        view.apply {
                            isVisible = isIn
                            clearAnimation()
                        }
                      
                    }

                    override fun onAnimationRepeat(animation: Animation?) {
                    }
                })
            }
        view.startAnimation(animation)
    }
//调用时如下
binding.clDialogFinish.isVisible = true
animationInOrOut(binding.clDialogFinish, R.anim.dialog_in)

         

你可能感兴趣的:(学习记录,学习,android,kotlin)