HokoBlurDrawable icon indicating copy to clipboard operation
HokoBlurDrawable copied to clipboard

裁剪圆角

Open mrbattery1130 opened this issue 4 years ago • 1 comments

尝试使用minminaya/GenaralRoundLayout的方法给BlurFrameLayout添加圆角,结果模糊消失。有没有什么方法可以让BlurDrawable支持圆角? 代码如下

class BlurFrameLayout : FrameLayout, IRoundView {

    private lateinit var generalRoundViewImpl: GeneralRoundViewImpl

    var blurDrawable: BlurDrawable = BlurDrawable()
        private set

    constructor(context: Context?) : super(context!!) {
        init(null)
    }

    constructor(context: Context?, attrs: AttributeSet?) : super(
        context!!, attrs
    ) {
        init(attrs)
    }

    constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(
        context!!, attrs, defStyleAttr
    ) {
        init(attrs)
    }

    private fun init(attrs: AttributeSet?) {
        generalRoundViewImpl = GeneralRoundViewImpl(
            this, context, attrs,
            R.styleable.BlurFrameLayout,
            R.styleable.BlurFrameLayout_corner_radius
        )
        background = blurDrawable
    }

    override fun onDetachedFromWindow() {
        super.onDetachedFromWindow()
        blurDrawable.freeGLResource()
    }

    override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
        super.onLayout(changed, left, top, right, bottom)
        generalRoundViewImpl.onLayout(changed, left, top, right, bottom)
    }

    override fun dispatchDraw(canvas: Canvas?) {
        generalRoundViewImpl.beforeDispatchDraw(canvas)
        super.dispatchDraw(canvas)
        generalRoundViewImpl.afterDispatchDraw(canvas)
    }

    override fun setCornerRadius(cornerRadius: Float) {
        generalRoundViewImpl.setCornerRadius(cornerRadius)
    }
}

mrbattery1130 avatar Oct 20 '21 02:10 mrbattery1130

这个方案无法支持圆角

因为圆角且clip的布局,实际上会生成新的layer,这个新的layer会先于root node绘制,所以无法获取到后面的内容

patrickKXMD avatar May 30 '22 12:05 patrickKXMD