I\'ve got a Linearlayout which I\'ve made transparent, and now I\'m looking for a way to give it a Blur effect, so what\'s ever underneath it gets blurry. Just like the Wind
step 1. cut the part of background image in bitmap which is to be blured.
step 2. Blur that part of bitmap.
step 3. set bitmap as a background.
private void applyBlur(final View image, final View layout) {
image.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
image.getViewTreeObserver().removeOnPreDrawListener(this);
image.buildDrawingCache();
Bitmap bmp = image.getDrawingCache();
Bitmap overlay = Bitmap.createBitmap((int) (layout.getMeasuredWidth()),
(int) (layout.getMeasuredHeight()), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(overlay);
canvas.translate(-layout.getLeft(), -layout.getTop());
canvas.drawBitmap(bmp, 0, 0, null);
RenderScript rs = RenderScript.create(getActivity());
Allocation overlayAlloc = Allocation.createFromBitmap(
rs, overlay);
ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(
rs, overlayAlloc.getElement());
blur.setInput(overlayAlloc);
blur.setRadius(20);
blur.forEach(overlayAlloc);
overlayAlloc.copyTo(overlay);
layout.setBackground(new BitmapDrawable(
getResources(), overlay));
rs.destroy();
return true;
}
});
}
now call this function:
applyBlur(detail_main_image, titleLayout);
//where detail_main_image is image on which i have to show blur part //and titleLayout is view on which i have to set background blur.