Android模糊视图(视图后面的模糊背景) [英] Android Blur View (Blur background behind the view)

查看:211
本文介绍了Android模糊视图(视图后面的模糊背景)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使图像的底部模糊,使其像图像中的顶部视图一样。



我尝试使用Rendenscript对其进行模糊处理,但我无法仅模糊视图后面的部分。 :(



我看过很多库,但是几乎所有库都模糊了整个图像,但不是其中一部分。



另外,重要的一点是我正在ViewPager中使用它,因此需要快速而动态地类似

解决方案

将这两个类添加到您的应用中,



1> BlurKit.Java

 公共类BlurKit {

private静态BlurKit实例;

私人RenderScript rs;

public static void init(Context context){
if(instance!= null){
return;
}

实例= new BlurKit();
instance.rs = RenderScript.create(context);
}

public Bitmap blur(Bitmap src,int radius){
最终分配输入= Allocation.createFromBitmap(rs,src);
最终分配输出= Allocation.createTyped(rs,input.getType());
最终的ScriptIntrinsicBlur脚本;
if(android.os.Build.VERSION.SDK_INT> = android.os.Build.VERSION_CODES.JELLY_BEAN_MR1){
script = ScriptIntrinsicBlur.create(rs,Element.U8_4(rs));
script.setRadius(radius);
script.setInput(input);
script.forEach(输出);
}
output.copyTo(src);
return src;
}

public Bitmap blur(View src,int radius){
Bitmap bitmap = getBitmapForView(src,1f);
return blur(位图,半径);
}

public Bitmap fastBlur(View src,int radius,float downscaleFactor){
Bitmap bitmap = getBitmapForView(src,downscaleFactor);
return blur(位图,半径);
}

私有位图getBitmapForView(View src,float downscaleFactor){
位图位图= Bitmap.createBitmap(
(int)(src.getWidth()* downscaleFactor ),
(int)(src.getHeight()* downscaleFactor),
Bitmap.Config.ARGB_4444
);

Canvas canvas = new Canvas(bitmap);
Matrix matrix = new Matrix();
matrix.preScale(downscaleFactor,downscaleFactor);
canvas.setMatrix(matrix);
src.draw(画布);

返回位图;
}

公共静态BlurKit getInstance(){
if(instance == null){
throw new RuntimeException( BlurKit未初始化!);
}

返回实例;
}

}

2> BlurLayout.Java

 公共类BlurLayout扩展了FrameLayout {

public static final float DEFAULT_DOWNSCALE_FACTOR = 0.12f;
public static final int DEFAULT_BLUR_RADIUS = 12;
public static final int DEFAULT_FPS = 60;

//可自定义的属性

/ **用于在模糊之前缩放视图位图的因子。 * /
私人浮点数mDownscaleFactor;

/ **模糊半径直接传递给stackblur库。 * /
private int mBlurRadius;

/ **每秒执行的模糊失效次数。 * /
private int mFPS;

//计算的类依赖性

/ **引用View到上层父级。有关检索,请参见{@link #getActivityView()getActivityView}。 * /
private WeakReference< View> mActivityView;

public BlurLayout(Context context){
super(context,null);
}

public BlurLayout(Context context,AttributeSet attrs){
super(context,attrs);
BlurKit.init(上下文);

TypedArray a = context.getTheme()。obtainStyledAttributes(
attrs,
R.styleable.BlurLayout,
0,0);

试试{
mDownscaleFactor = a.getFloat(R.styleable.BlurLayout_downscaleFactor,DEFAULT_DOWNSCALE_FACTOR);
mBlurRadius = a.getInteger(R.styleable.BlurLayout_blurRadius,DEFAULT_BLUR_RADIUS);
mFPS = a.getInteger(R.styleable.BlurLayout_fps,DEFAULT_FPS);
}最终{
a.recycle();
}

if(mFPS> 0){
Choreographer.getInstance()。postFrameCallback(invalidationLoop);
}
}

/ **编舞者回调,可重新绘制模糊并安排另一个回调。 * /
private Choreographer.FrameCallback invalidationLoop = new Choreographer.FrameCallback(){
@Override
public void doFrame(long frameTimeNanos){
invalidate();
Choreographer.getInstance()。postFrameCallbackDelayed(this,1000 / mFPS);
}
};

/ **
* {@inheritDoc}
* /
@Override
public void invalidate(){
super.invalidate( );
位图bitmap = blur();
if(bitmap!= null){
setBackground(new BitmapDrawable(bitmap));
}
}

/ **
*重新创建内容的模糊并将其设置为背景。
* /
私人位图blur(){
if(getContext()== null){
返回null;
}

//检查对父视图的引用。
//如果不可用,请尝试使其成功。
if(mActivityView == null || mActivityView.get()== null){
mActivityView = new WeakReference<>(getActivityView());
if(mActivityView.get()== null){
返回null;
}
}

//计算相对于父视图的相对点。
Point pointRelativeToActivityView = getPositionInScreen();

//在创建父视图位图之前将alpha设置为0。
//模糊视图在创建的位图中不可见。
setAlpha(0);

//绑定检查的屏幕大小
int screenWidth = mActivityView.get()。getWidth();
int screenHeight = mActivityView.get()。getHeight();

//模糊位图的最终尺寸。
int width =(int)(getWidth()* mDownscaleFactor);
int height =(int)(getHeight()* mDownscaleFactor);

//裁剪位图的X / Y位置。
int x =(int)(pointRelativeToActivityView.x * mDownscaleFactor);
int y =(int)(pointRelativeToActivityView.y * mDownscaleFactor);

//填充以添加到作物预模糊中。
//直接模糊到边缘会有副作用,因此添加了填充。
int xPadding = getWidth()/ 8;
int yPadding = getHeight()/ 8;

//独立计算每一边的填充,检查边线。
int leftOffset = -xPadding;
leftOffset = x + leftOffset> = 0? leftOffset:0;

int rightOffset = xPadding;
rightOffset = x + getWidth()+ rightOffset< =屏幕宽度? rightOffset:screenWidth-getWidth()-x;

int topOffset = -yPadding;
topOffset = y + topOffset> = 0? topOffset:0;

int bottomOffset = yPadding;
bottomOffset = y +高度+ bottomOffset< = screenHeight? bottomOffset:0;

//创建父视图位图,使用上面的填充裁剪到BlurLayout区域。
位图位图;
try {
bitmap = getDownscaledBitmapForView(
mActivityView.get(),
new Rect(
pointRelativeToActivityView.x + leftOffset,
pointRelativeToActivityView.y + topOffset ,
pointRelativeToActivityView.x + getWidth()+ Math.abs(leftOffset)+ rightOffset,
pointRelativeToActivityView.y + getHeight()+ Math.abs(topOffset)+ bottomOffset
),
mDownscaleFactor
);
} catch(NullPointerException e){
返回null;
}

//模糊位图。
位图= BlurKit.getInstance()。blur(位图,mBlurRadius);

//再次裁剪位图以删除填充。
位图= Bitmap.createBitmap(
位图,
(int)(Math.abs(leftOffset)* mDownscaleFactor),
(int)(Math.abs(topOffset)* mDownscaleFactor ),宽度
,高度

);

//再次显示自我。
setAlpha(1);

//将背景设置为模糊位图。
返回位图;
}

/ **
*将上下文转换为Activity并尝试使用窗口装饰视图创建视图引用。
* @return查看整个活动的参考。
* /
private View getActivityView(){
活动活动;
try {
activity =(Activity)getContext();
} catch(ClassCastException e){
返回null;
}

返回activity.getWindow()。getDecorView()。findViewById(android.R.id.content);
}

/ **
*返回屏幕上的位置。保留为抽象,以允许特定的实现,例如
*缓存行为。
* /
private Point getPositionInScreen(){
return getPositionInScreen(this);
}

/ **
*查找父视图的Point,并通过self getX()和getY()抵消结果。
* @return Point确定传入的视图在其所有ViewParent中的位置。
* /
私有Point getPositionInScreen(View view){
if(getParent()== null){
返回新的Point();
}


ViewGroup父级;
try {
parent =(ViewGroup)view.getParent();
} catch(Exception e){
return new Point();
}

if(parent == null){
return new Point();
}

Point point = getPositionInScreen(parent);
point.offset((int)view.getX(),(int)view.getY());
返回点;
}

/ **
*用户使用View引用创建位图,并使用传入的因子缩小其比例。
*使用矩形将视图裁剪到位图中。
* @return从视图制作的位图,由downscaleFactor缩减。
* @throws NullPointerException
* /
私有Bitmap getDownscaledBitmapForView(View view,Rect crop,float downscaleFactor)throws NullPointerException {
View screenView = view.getRootView();

int width =(int)(crop.width()* downscaleFactor);
int height =(int)(crop.height()* downscaleFactor);

if(screenView.getWidth()< = 0 || screenView.getHeight()< = 0 || width< = 0 || height< = 0){
抛出新的NullPointerException();
}

float dx = -crop.left * downscaleFactor;
float dy = -crop.top * downscaleFactor;

位图位图= Bitmap.createBitmap(width,height,Bitmap.Config.ARGB_4444);
Canvas canvas = new Canvas(bitmap);
Matrix matrix = new Matrix();
matrix.preScale(downscaleFactor,downscaleFactor);
matrix.postTranslate(dx,dy);
canvas.setMatrix(matrix);
screenView.draw(canvas);

返回位图;
}

/ **
*设置缩小系数以使用预模糊。
*参见{@link #mDownscaleFactor}。
* /
public void setDownscaleFactor(float downscaleFactor){
this.mDownscaleFactor = downscaleFactor;
invalidate();
}

/ **
*设置要在缩小位图上使用的模糊半径。
*参见{@link #mBlurRadius}。
* /
public void setBlurRadius(int blurRadius){
this.mBlurRadius = blurRadius;
invalidate();
}

/ **
*设置FPS以使模糊失效。
*参见{@link #mFPS}。
* /
public void setFPS(int fps){
this.mFPS = fps;
}

}

在XML文件中:

 < FrameLayout 
android:id = @ + id / fl_uploadedView
android:layout_width = match_parent
android:layout_height = wrap_content
android:layout_margin = @ dimen / _10sdp>

< ImageView
android:id = @ + id / dv_uploadedPic
android:layout_width = match_parent
android:layout_height = @ dimen / _150sdp
android:contentDescription = @ string / app_name
android:scaleType = centerCrop
android:src = @ color / gray />

< BlurLayout
android:id = @ + id / ll_blurView
android:layout_width = match_parent
android:layout_height = wrap_content
android:layout_gravity = bottom>

< TextView
android:id = @ + id / tv_fileName
android:layout_width = match_parent
android:layout_height = wrap_content
android:layout_gravity = left
android:padding = @ dimen / _5sdp
android:textSize = @ dimen / _10sdp
/>
< / BlurLayout>
< / FrameLayout>

别忘了将此内容添加到
values> attr.xml中

 <!-
模糊布局开始
->
< declare-styleable name = BlurLayout>
< attr name = downscaleFactor format = float />
< attr name = blurRadius format = integer />
< attr name = fps format = integer />
< / declare-styleable>

< ;!-
模糊布局结束
->


I am trying to make the bottom part of an Image blur for the view on top it like in the image.

I tried blurring it using Rendenscript but I am not able to blur only the part behind the view. :(

I have seen many libraries but almost all of them blur the entire image, but not a part of it.

Also, an important part is that I am using this inside a ViewPager and hence needs to be fast and dynamic something like this in IOS which redraws itself the moment image behind it changes.

Any help is appreciated. Thanks for stopping by!

My xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/image"
        android:src="@drawable/broadstairs"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="centerCrop"
        android:layout_centerInParent="true"/>

    <TextView
        android:id="@+id/text"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:text="Hello World"
        android:gravity="center"
        android:layout_alignParentBottom="true"
        android:textColor="@android:color/white"
        android:textStyle="bold"
        android:textSize="36sp"/>
</RelativeLayout>

My code:

BlurBuilder.java

public class BlurBuilder {
    private static final float BITMAP_SCALE = 0.1f;
    private static final float BLUR_RADIUS = 7.5f;

    public static Bitmap blur(Context context, Bitmap image) {
        int width = Math.round(image.getWidth() * BITMAP_SCALE);
        int height = Math.round(image.getHeight() * BITMAP_SCALE);

        Bitmap inputBitmap = Bitmap.createScaledBitmap(image, width, height, false);
        Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap);

        RenderScript rs = RenderScript.create(context);
        ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
        Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap);
        Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);
        theIntrinsic.setRadius(BLUR_RADIUS);
        theIntrinsic.setInput(tmpIn);
        theIntrinsic.forEach(tmpOut);
        tmpOut.copyTo(outputBitmap);

        return outputBitmap;
    }

    @SuppressLint("NewApi")
    public static void blur(final Context context, final Bitmap bitmap, final View view) {

        new AsyncTask<Void, Void, Bitmap>() {

            @Override
            protected Bitmap doInBackground(Void... params) {
                Paint paint = new Paint();
                paint.setFilterBitmap(true);
                Bitmap cropImage = Bitmap.createBitmap(bitmap, 0, bitmap.getHeight() - view.getHeight(), bitmap.getWidth(), view.getHeight());

                return BlurBuilder.blur(context, cropImage);
            }


            @Override
            protected void onPostExecute(Bitmap bitmap) {
                super.onPostExecute(bitmap);
                if (bitmap != null) {
                    int sdk = android.os.Build.VERSION.SDK_INT;
                    if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
                        view.setBackgroundDrawable(new BitmapDrawable(context.getResources(), bitmap));
                    } else {
                        view.setBackground(new BitmapDrawable(context.getResources(), bitmap));
                    }

                }

            }
        }.execute();


    }

}

In my MainActivity's onCreate I do:

BlurBuilder.blur(BitmapActivity.this, ((BitmapDrawable) mView.getDrawable()).getBitmap(), mDummyView);

Below is the result:

解决方案

Add these two classes to your app,

1> BlurKit.Java

public class BlurKit {

    private static BlurKit instance;

    private RenderScript rs;

    public static void init(Context context) {
        if (instance != null) {
            return;
        }

        instance = new BlurKit();
        instance.rs = RenderScript.create(context);
    }

    public Bitmap blur(Bitmap src, int radius) {
        final Allocation input = Allocation.createFromBitmap(rs, src);
        final Allocation output = Allocation.createTyped(rs, input.getType());
        final ScriptIntrinsicBlur script;
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
            script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
            script.setRadius(radius);
            script.setInput(input);
            script.forEach(output);
        }
        output.copyTo(src);
        return src;
    }

    public Bitmap blur(View src, int radius) {
        Bitmap bitmap = getBitmapForView(src, 1f);
        return blur(bitmap, radius);
    }

    public Bitmap fastBlur(View src, int radius, float downscaleFactor) {
        Bitmap bitmap = getBitmapForView(src, downscaleFactor);
        return blur(bitmap, radius);
    }

    private Bitmap getBitmapForView(View src, float downscaleFactor) {
        Bitmap bitmap = Bitmap.createBitmap(
                (int) (src.getWidth() * downscaleFactor),
                (int) (src.getHeight() * downscaleFactor),
                Bitmap.Config.ARGB_4444
        );

        Canvas canvas = new Canvas(bitmap);
        Matrix matrix = new Matrix();
        matrix.preScale(downscaleFactor, downscaleFactor);
        canvas.setMatrix(matrix);
        src.draw(canvas);

        return bitmap;
    }

    public static BlurKit getInstance() {
        if (instance == null) {
            throw new RuntimeException("BlurKit not initialized!");
        }

        return instance;
    }

}

2> BlurLayout.Java

public class BlurLayout extends FrameLayout {

    public static final float DEFAULT_DOWNSCALE_FACTOR = 0.12f;
    public static final int DEFAULT_BLUR_RADIUS = 12;
    public static final int DEFAULT_FPS = 60;

    // Customizable attributes

    /** Factor to scale the view bitmap with before blurring. */
    private float mDownscaleFactor;

    /** Blur radius passed directly to stackblur library. */
    private int mBlurRadius;

    /** Number of blur invalidations to do per second.  */
    private int mFPS;

    // Calculated class dependencies

    /** Reference to View for top-parent. For retrieval see {@link #getActivityView() getActivityView}. */
    private WeakReference<View> mActivityView;

    public BlurLayout(Context context) {
        super(context, null);
    }

    public BlurLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        BlurKit.init(context);

        TypedArray a = context.getTheme().obtainStyledAttributes(
                attrs,
                R.styleable.BlurLayout,
                0, 0);

        try {
            mDownscaleFactor = a.getFloat(R.styleable.BlurLayout_downscaleFactor, DEFAULT_DOWNSCALE_FACTOR);
            mBlurRadius = a.getInteger(R.styleable.BlurLayout_blurRadius, DEFAULT_BLUR_RADIUS);
            mFPS = a.getInteger(R.styleable.BlurLayout_fps, DEFAULT_FPS);
        } finally {
            a.recycle();
        }

        if (mFPS > 0) {
            Choreographer.getInstance().postFrameCallback(invalidationLoop);
        }
    }

    /** Choreographer callback that re-draws the blur and schedules another callback. */
    private Choreographer.FrameCallback invalidationLoop = new Choreographer.FrameCallback() {
        @Override
        public void doFrame(long frameTimeNanos) {
            invalidate();
            Choreographer.getInstance().postFrameCallbackDelayed(this, 1000 / mFPS);
        }
    };

    /**
     * {@inheritDoc}
     */
    @Override
    public void invalidate() {
        super.invalidate();
        Bitmap bitmap = blur();
        if (bitmap != null) {
            setBackground(new BitmapDrawable(bitmap));
        }
    }

    /**
     * Recreates blur for content and sets it as the background.
     */
    private Bitmap blur() {
        if (getContext() == null) {
            return null;
        }

        // Check the reference to the parent view.
        // If not available, attempt to make it.
        if (mActivityView == null || mActivityView.get() == null) {
            mActivityView = new WeakReference<>(getActivityView());
            if (mActivityView.get() == null) {
                return null;
            }
        }

        // Calculate the relative point to the parent view.
        Point pointRelativeToActivityView = getPositionInScreen();

        // Set alpha to 0 before creating the parent view bitmap.
        // The blur view shouldn't be visible in the created bitmap.
        setAlpha(0);

        // Screen sizes for bound checks
        int screenWidth = mActivityView.get().getWidth();
        int screenHeight = mActivityView.get().getHeight();

        // The final dimensions of the blurred bitmap.
        int width = (int) (getWidth() * mDownscaleFactor);
        int height = (int) (getHeight() * mDownscaleFactor);

        // The X/Y position of where to crop the bitmap.
        int x = (int) (pointRelativeToActivityView.x * mDownscaleFactor);
        int y = (int) (pointRelativeToActivityView.y * mDownscaleFactor);

        // Padding to add to crop pre-blur.
        // Blurring straight to edges has side-effects so padding is added.
        int xPadding = getWidth() / 8;
        int yPadding = getHeight() / 8;

        // Calculate padding independently for each side, checking edges.
        int leftOffset = -xPadding;
        leftOffset = x + leftOffset >= 0 ? leftOffset : 0;

        int rightOffset = xPadding;
        rightOffset = x + getWidth() + rightOffset <= screenWidth ? rightOffset : screenWidth - getWidth() - x;

        int topOffset = -yPadding;
        topOffset = y + topOffset >= 0 ? topOffset : 0;

        int bottomOffset = yPadding;
        bottomOffset = y + height + bottomOffset <= screenHeight ? bottomOffset : 0;

        // Create parent view bitmap, cropped to the BlurLayout area with above padding.
        Bitmap bitmap;
        try {
            bitmap = getDownscaledBitmapForView(
                    mActivityView.get(),
                    new Rect(
                            pointRelativeToActivityView.x + leftOffset,
                            pointRelativeToActivityView.y + topOffset,
                            pointRelativeToActivityView.x + getWidth() + Math.abs(leftOffset) + rightOffset,
                            pointRelativeToActivityView.y + getHeight() + Math.abs(topOffset) + bottomOffset
                    ),
                    mDownscaleFactor
            );
        } catch (NullPointerException e) {
            return null;
        }

        // Blur the bitmap.
        bitmap = BlurKit.getInstance().blur(bitmap, mBlurRadius);

        //Crop the bitmap again to remove the padding.
        bitmap = Bitmap.createBitmap(
                bitmap,
                (int) (Math.abs(leftOffset) * mDownscaleFactor),
                (int) (Math.abs(topOffset) * mDownscaleFactor),
                width,
                height
        );

        // Make self visible again.
        setAlpha(1);

        // Set background as blurred bitmap.
        return bitmap;
    }

    /**
     * Casts context to Activity and attempts to create a view reference using the window decor view.
     * @return View reference for whole activity.
     */
    private View getActivityView() {
        Activity activity;
        try {
            activity = (Activity) getContext();
        } catch (ClassCastException e) {
            return null;
        }

        return activity.getWindow().getDecorView().findViewById(android.R.id.content);
    }

    /**
     * Returns the position in screen. Left abstract to allow for specific implementations such as
     * caching behavior.
     */
    private Point getPositionInScreen() {
        return getPositionInScreen(this);
    }

    /**
     * Finds the Point of the parent view, and offsets result by self getX() and getY().
     * @return Point determining position of the passed in view inside all of its ViewParents.
     */
    private Point getPositionInScreen(View view) {
        if (getParent() == null) {
            return new Point();
        }


        ViewGroup parent;
        try {
            parent = (ViewGroup) view.getParent();
        } catch (Exception e) {
            return new Point();
        }

        if (parent == null) {
            return new Point();
        }

        Point point = getPositionInScreen(parent);
        point.offset((int) view.getX(), (int) view.getY());
        return point;
    }

    /**
     * Users a View reference to create a bitmap, and downscales it using the passed in factor.
     * Uses a Rect to crop the view into the bitmap.
     * @return Bitmap made from view, downscaled by downscaleFactor.
     * @throws NullPointerException
     */
    private Bitmap getDownscaledBitmapForView(View view, Rect crop, float downscaleFactor) throws NullPointerException {
        View screenView = view.getRootView();

        int width = (int) (crop.width() * downscaleFactor);
        int height = (int) (crop.height() * downscaleFactor);

        if (screenView.getWidth() <= 0 || screenView.getHeight() <= 0 || width <= 0 || height <= 0) {
            throw new NullPointerException();
        }

        float dx = -crop.left * downscaleFactor;
        float dy = -crop.top * downscaleFactor;

        Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444);
        Canvas canvas = new Canvas(bitmap);
        Matrix matrix = new Matrix();
        matrix.preScale(downscaleFactor, downscaleFactor);
        matrix.postTranslate(dx, dy);
        canvas.setMatrix(matrix);
        screenView.draw(canvas);

        return bitmap;
    }

    /**
     * Sets downscale factor to use pre-blur.
     * See {@link #mDownscaleFactor}.
     */
    public void setDownscaleFactor(float downscaleFactor) {
        this.mDownscaleFactor = downscaleFactor;
        invalidate();
    }

    /**
     * Sets blur radius to use on downscaled bitmap.
     * See {@link #mBlurRadius}.
     */
    public void setBlurRadius(int blurRadius) {
        this.mBlurRadius = blurRadius;
        invalidate();
    }

    /**
     * Sets FPS to invalidate blur with.
     * See {@link #mFPS}.
     */
    public void setFPS(int fps) {
        this.mFPS = fps;
    }

}

in XML file:

               <FrameLayout
                        android:id="@+id/fl_uploadedView"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_margin="@dimen/_10sdp">

                        <ImageView
                            android:id="@+id/dv_uploadedPic"
                            android:layout_width="match_parent"
                            android:layout_height="@dimen/_150sdp"
                            android:contentDescription="@string/app_name"
                            android:scaleType="centerCrop"
                            android:src="@color/gray" />

                        <BlurLayout
                            android:id="@+id/ll_blurView"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_gravity="bottom">

                        <TextView
                            android:id="@+id/tv_fileName"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_gravity="left"
                            android:padding="@dimen/_5sdp"
                            android:textSize="@dimen/_10sdp"
                           />
                </BlurLayout>
            </FrameLayout>

Do not forget to add this to values > attr.xml

<!--
         Blur Layout start
      -->
    <declare-styleable name="BlurLayout">
        <attr name="downscaleFactor" format="float" />
        <attr name="blurRadius" format="integer" />
        <attr name="fps" format="integer" />
    </declare-styleable>

    <!--
       Blur Layout end
    -->

这篇关于Android模糊视图(视图后面的模糊背景)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆