我创建了一个活动透明,它的中心布局是不透明的。我想要的是之前的活动(可以看到)应该是模糊的。我试过不透明,但没用。
我想做一个透明的布局 parentRelative
模糊。
透明性.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/parentRelative"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:layout_margin="30dp"
tools:context=".TransparentActivity">
<RelativeLayout
android:id="@+id/secondParentRelative"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true">
...
</RelativeLayout>
</RelativeLayout>
透明性.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
RelativeLayout relativeLayout = findViewById(R.id.parentRelative);
relativeLayout.setBackground(new BitmapDrawable(getResources(),
blur(TransparentActivity.this, captureScreenShot(relativeLayout))));
}
public static Bitmap captureScreenShot(View view) {
Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_4444);
Canvas canvas = new Canvas(bitmap);
Drawable backgroundDrawable = view.getBackground();
if (backgroundDrawable != null) {
backgroundDrawable.draw(canvas);
} else {
canvas.drawColor(Color.parseColor("#80000000"));
}
view.draw(canvas);
return bitmap;
}
public static Bitmap blur(Context context, Bitmap image) {
float BITMAP_SCALE = 0.4f;
float BLUR_RADIUS = 23f;
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;
}
这个 blur
以及 captureScreenShot
是我从其他人那里得到的答案。但它不起作用。
我想使透明的布局模糊。
有人能告诉我我错过了什么吗?
暂无答案!
目前还没有任何答案,快来回答吧!