我有一个列表视图和一个位于列表视图前面的布局。我希望该布局以他背后的列表视图的模糊为背景。就像图片中一样。模糊根据列表视图滚动而变化。我该怎么做呢?
问问题
1694 次
2 回答
4
这个库是你需要的https://github.com/Dimezis/BlurView
<eightbitlab.com.blurview.BlurView
android:id="@+id/blurView"
android:layout_width="match_parent"
android:layout_height="66dp"
android:layout_alignParentBottom="true"
>
<!--anything below this view will be blured-->
</eightbitlab.com.blurview.BlurView>
在 app.gradle defaultConfig
renderscriptTargetApi 23
renderscriptSupportModeEnabled true
并且在活动中
blurView = (BlurView) findViewById(R.id.blurView);
final View decorView = getWindow().getDecorView();
final View rootView = decorView.findViewById(android.R.id.content);
final Drawable windowBackground = decorView.getBackground();
blurView.setupWith(rootView)
.windowBackground(windowBackground)
.blurAlgorithm(new RenderScriptBlur(this, true)) //Preferable algorithm, needs RenderScript support mode enabled
.blurRadius(10);
于 2016-08-10T18:13:53.607 回答
0
参考了这篇博文
private void blur(Bitmap bkg, View view, float radius) {
Bitmap overlay = Bitmap.createBitmap(
view.getMeasuredWidth(),
view.getMeasuredHeight(),
Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(overlay);
canvas.drawBitmap(bkg, -view.getLeft(),
-view.getTop(), null);
RenderScript rs = RenderScript.create(this);
Allocation overlayAlloc = Allocation.createFromBitmap(
rs, overlay);
ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(
rs, overlayAlloc.getElement());
blur.setInput(overlayAlloc);
blur.setRadius(radius);
blur.forEach(overlayAlloc);
overlayAlloc.copyTo(overlay);
view.setBackground(new BitmapDrawable(
getResources(), overlay));
rs.destroy();
}
于 2016-04-03T19:24:24.130 回答