흐릿한 투명한 배경 효과 만들기
배경이 투명 할뿐만 아니라 흐림 효과도있는 뷰를 만들려고합니다. 이렇게하면 아래의 뷰가 초점이 맞지 않는 것처럼 보입니다. 전원 버튼을 누른 상태에서 화면이 보이는 것처럼 보이기를 원합니다. 어떤 아이디어?
이제 창 플래그가 더 이상 사용되지 않으므로 자신을 흐리게 처리해야합니다. 나는 이것을 다른 곳에서 대답했지만 다음은 뷰를 흐리게 처리하는 방법입니다.
이제 사용할 수 있습니다 ScriptIntrinsicBlur을 신속하게 흐리게하는 RenderScript 라이브러리에서. 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 is included into support v8 enabling this answer down to api 8. To enable it using gradle include these lines into your gradle file (from this answer) and use Renderscript from package android.support.v8.renderscript:
android {
...
defaultConfig {
...
renderscriptTargetApi *your target api*
renderscriptSupportModeEnabled true
}
...
}
If all you want to do is blur the background of the window behind your activty then you can use this call from within your activity (or any class, like an AlertDialog that has a window)
getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
Update: this flag was deprecated in Android 4.0 and no longer works.
Blurry is a nice option which will easily give you the effect you are looking for: https://github.com/wasabeef/Blurry
after adding it to project, wrap the view you want to blur in a FrameLayout, then use this line when you want to blur:
Blurry.with(this).radius(25).sampling(2).onto((ViewGroup) findViewById(R.id.viewToBlurWrapper));
참고URL : https://stackoverflow.com/questions/6795483/create-blurry-transparent-background-effect
'Nice programing' 카테고리의 다른 글
| golang에서 맵에서 값 조각을 얻는 좋은 방법이 있습니까? (0) | 2020.11.08 |
|---|---|
| 빌드 이벤트 명령 줄에 주석을 추가하는 올바른 방법은 무엇입니까? (0) | 2020.11.07 |
| 마우스를 올려도 "youtube"상단의 막대를 숨기는 방법은 무엇입니까? (0) | 2020.11.07 |
| Entity Framework Core에서 데이터베이스 자동 생성 (0) | 2020.11.07 |
| 이전 인터프리터 버전으로 인해 실패한 향후 기능 (__future__) 가져 오기를 정상적으로 처리하는 방법은 무엇입니까? (0) | 2020.11.07 |