Android: 模糊布局后面的列表视图
Android: Blur listview behind a layout
我有一个列表视图和一个位于列表视图前面的布局。我希望该布局以他背后的列表视图的模糊作为背景。就像在图像中。模糊根据列表视图滚动而变化。我该怎么做呢?
引用此博客post
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();
}
这个库就是你需要的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默认配置
renderscriptTargetApi 23
renderscriptSupportModeEnabled true
并在 activity
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);
我有一个列表视图和一个位于列表视图前面的布局。我希望该布局以他背后的列表视图的模糊作为背景。就像在图像中。模糊根据列表视图滚动而变化。我该怎么做呢?
引用此博客post
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();
}
这个库就是你需要的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默认配置
renderscriptTargetApi 23
renderscriptSupportModeEnabled true
并在 activity
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);