I have pretty complex solution, so there won't be any code. So, here is idea, step by step:
- Let's assume that your layout have just single custom
LinearLayout
. NoImageView
as a background. - What we going to do, is draw background drawable of
LinearLayout
by our own, so it will first draw full image and then draw blurred square from the same image on top. Content ofLinearLayout
might be moved to desired position using paddings. - So, create something like
MyLinearLayout
and put it to your layout resource. Provide required constructors. - Override
onAttachedToWindow()
andonDetachedFromWindow()
methods. Inside them we should load our backgroundBitmap
and recycle it accordingly. Let's name itmBackground
- Override
draw()
method. Inside it we're going to first draw ourmBackground
. - Then, you can use
Canvas#clipRect()
method to crop drawing area ofCanvas
to some specified rectangle. In your case, this rectangle should be the area below your content. You can figure it out usingView#getPadding*()
methods. Don't forget to callcanvas#save()
before clipping drawing area. - Now you can draw your bitmap once again with blur (I don't know which method exactly you're using, so let's assume that you know how to do it... but you still can share it with us :) ). Cool thing is that you can just draw the same
Bitmap
once again in full scale - since we had calledclipRect
before, it will be drawn only within this area. Don't forget to callcanvas#restore()
after drawing background. - Call
super.draw()
to draw rest of the stuff, that yourLinearLayout
contains.