前言
写这个东西主要是想把这个东西记下来,根据实际使用的情况来看,有些分辨率高的手机进行模糊所花费的时间有点长,使用动画进行掩饰后,发现这个方法可能在不同的手机上有掉帧的情况,进行高斯模糊的性能比较低,最后被同事弃用,但是我觉得弃之可惜,毕竟一种方法总有可取之处,特此记录下来。
实现思路
1. 对背景屏幕进行截屏
2. 对截屏的图片进行高斯模糊
3. 将进行模糊的图片设置为Dialog的背景
4. 在图片上面覆盖一层布局,这个布局主要的作用就是让最后表现为某某颜色的半透明状态。
代码实现
dialog_blur_bg_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/iv_blur_show"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"/>
<ImageView
android:id="@+id/iv_blur_alpha"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#77000000"/>
<FrameLayout
android:id="@+id/fl_add_views"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"/>
</RelativeLayout>
import android.app.Activity;
import android.app.Dialog;
import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.vi