透明なだけでなく、ぼかし効果も持つ背景を持つビューを作成しようとしています。そうすることで、下のビューは焦点が外れているように見えます。電源ボタンを押したまま画面が見えるようにしたい。何か案は?ぼんやりした透明な背景効果を作成する
答えて
ウィンドウフラグが廃止されたので、自分自身をぼかす必要があります。他の場所でこれに答えましたが、ビューをぼかす方法は次のとおりです。
レンダースクリプトライブラリの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. 透明な背景を持つ透明な背景でムービーを作る方法
- 3. 透明でない背景に透明なテキストを作成する方法
- 4. 透明な背景
- 5. WP7背景のぼかしの効果
- 6. 透明な背景でCSS折りたたみコーナーエフェクトを作成するには?
- 7. FFMPEG:lavfiで透明な背景を作成しますか?
- 8. 透明な背景でテキストも透明になります
- 9. javafx2.2透明な背景を持つスクロールバーを作成する
- 10. 透明な背景を持つUIImageを作成する方法
- 11. 透明な背景でuiviewを作成する方法は?
- 12. ランチャーアプリケーションアイコンの透明な背景を作成する方法
- 13. 透明なsvg要素を背景画像で作成する
- 14. ImageMagickで透明な背景画像を作成する
- 15. ぼんやりとした背景画像
- 16. 透明に設定しても透明な背景はありません。
- 17. SVG透明な背景Web
- 18. WPF透明な背景
- 19. PHP/GD - 透明な背景
- 20. スクロールナビゲーションコントローラビュー透明な背景
- 21. PyQt5 QGraphicsView透明な背景
- 22. PHP:透明な背景
- 23. 透明な背景のアーティファクト
- 24. Wordpressコメント透明な背景
- 25. UIVisualEffects、UIWebView透明な背景
- 26. Recyclerview透明な背景
- 27. 透明なボタンの背景
- 28. iframe透明な背景
- 29. 透明なウィジェットの背景?
- 30. 透明な背景のみ
あなたは揺れます。これは真剣に私を助けました。私が追加したことの1つは、ぼかし関数から返されるビットマップがTransitionDrawableだということです。これは、ぼかし効果をよりスムーズに見せるのに役立ちます。 –
これは素晴らしいです。ありがとうございました! –
BITMAP_SCALE定数とBLUR_RADIUS定数がどのように機能するかについての注意が必要ですか?ありがとうございます –