透明なだけでなく、ぼかし効果も持つ背景を持つビューを作成しようとしています。そうすることで、下のビューは焦点が外れているように見えます。電源ボタンを押したまま画面が見えるようにしたい。何か案は?ぼんやりした透明な背景効果を作成する
答えて
ウィンドウフラグが廃止されたので、自分自身をぼかす必要があります。他の場所でこれに答えましたが、ビューをぼかす方法は次のとおりです。
レンダースクリプトライブラリのScriptIntrinsicBlurをすぐにぼかして使用できるようになりました。 HereはRenderScript APIへのアクセス方法です。以下は、私がビューとビットマップをぼかすために作られたクラスです。
import android.support.v8.renderscript.*;
public class BlurBuilder {
private static final float BITMAP_SCALE = 0.4f;
private static final float BLUR_RADIUS = 7.5f;
public static Bitmap blur(View v) {
return blur(v.getContext(), getScreenshot(v));
}
public static Bitmap blur(Context ctx, 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(ctx);
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;
}
private static Bitmap getScreenshot(View v) {
Bitmap b = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
v.draw(c);
return b;
}
}
onCreateView
に以下を追加し、フラグメントにこれを適用するには:
final Activity activity = getActivity();
final View content = activity.findViewById(android.R.id.content).getRootView();
if (content.getWidth() > 0) {
Bitmap image = BlurBuilder.blur(content);
window.setBackgroundDrawable(new BitmapDrawable(activity.getResources(), image));
} else {
content.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Bitmap image = BlurBuilder.blur(content);
window.setBackgroundDrawable(new BitmapDrawable(activity.getResources(), image));
}
});
}
注:このソリューションは、に分SDKが必要ですAPIも17
EDIT:のrenderScriptはサポートV8に含まれているこの回答ダウを有効にします(このanswerから)あなたのGradleファイルに次の行を含めGradleのを使用してそれを有効にして、パッケージandroid.support.v8.renderscriptからのrenderScriptを使用するためのAPI 8にN:
android {
...
defaultConfig {
...
renderscriptTargetApi *your target api*
renderscriptSupportModeEnabled true
}
...
}
あなたがしたいすべては、あなたが(窓を持ってAlertDialogのように、または任意のクラス)あなたの活動の中から、このコールを使用することができ、あなたのactivtyの後ろのウィンドウの背景をぼかしている場合
getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
更新:このフラグはAndroid 4.0では廃止されましたが、もう動作しません。
私が探していたものです。それは有り難いです! –
これは廃止され、Android Lでは動作しなくなりました。 –
これは廃止予定です。回答を編集してください –
ぼやけがいいですそれはプロジェクト、あなたがでframeLayoutにぼかしたいビューをラップ、あなたはぼかしたいときに、このラインを使用するために追加した後 https://github.com/wasabeef/Blurry
:
簡単にあなたが探している効果を与えるオプション10Blurry.with(this).radius(25).sampling(2).onto((ViewGroup) findViewById(R.id.viewToBlurWrapper));
- 1. 透明な背景を持つ透明な背景でムービーを作る方法
- 2. WP7背景のぼかしの効果
- 3. 透明な背景
- 4. javafx2.2透明な背景を持つスクロールバーを作成する
- 5. 透明な背景を持つUIImageを作成する方法
- 6. ぼんやりとした背景画像
- 7. ImageMagickで透明な背景画像を作成する
- 8. AChartEngine透明な背景
- 9. 透明なボタンの背景
- 10. IEの透明な背景
- 11. Wordpressコメント透明な背景
- 12. PHP/GD - 透明な背景
- 13. 透明な背景のアーティファクト
- 14. iframe透明な背景
- 15. PHP:透明な背景
- 16. SDL RenderTextShaded透明な背景
- 17. 透明な背景のみ
- 18. UITextViewの透明な背景
- 19. 透明なウィジェットの背景?
- 20. SVG透明な背景Web
- 21. ウィンドウの背景内の透明穴を作成します - WPF
- 22. Android GLSurfaceView透明な背景setZOrderonTopなし
- 23. 透明な背景 - 完全に透明ではありません
- 24. 背景色を透明な背景画像で表示する
- 25. iOS 7で「ぼやけた」背景を持つ透視ボタンを作成する方法
- 26. jQuery UIアコーディオンまたはタブの透明な背景を作成するには?
- 27. 透明な背景イメージを通して背景色が見えるボタンを作成する方法は?
- 28. SharpGLとWPFを使用して透明な背景を作成する
- 29. Adobe Illustratorでスライスして透明な背景イメージを作成する
- 30. GDI +を使用して透明な背景でイメージを作成しますか?
あなたは揺れます。これは真剣に私を助けました。私が追加したことの1つは、ぼかし関数から返されるビットマップがTransitionDrawableだということです。これは、ぼかし効果をよりスムーズに見せるのに役立ちます。 –
これは素晴らしいです。ありがとうございました! –
BITMAP_SCALE定数とBLUR_RADIUS定数がどのように機能するかについての注意が必要ですか?ありがとうございます –