어떻게 안드로이드 투명 그라디언트 배경의 선형 레이아웃을 제공 할 수 있습니까? 레이아웃에는 배경이 흐리게 표시되어 있지만 레이아웃의 맨 위에 약간 흐리게 표시해야합니다. 그런 다음 그 아래에있는 불투명으로 이동하십시오.그라디언트 투명도가 적용된 Android 선형 레이아웃
레이아웃이 시차 스크롤 뷰에 중첩되어 레이아웃이 헤더 이미지의 맨 위로 슬라이드 될 수 있습니다.
나는 흐린 당김과 같이 생성 :final View content = img_header;
if (content.getWidth() > 0) {
Bitmap image = BlurBuilder.blur(content);
BitmapDrawable background = new BitmapDrawable(image);
ll_parent_layout.setBackground(background);
} else {
content.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Bitmap image = BlurBuilder.blur(content);
BitmapDrawable background = new BitmapDrawable(image);
ll_parent_layout.setBackground(background);
}
});
}
흐림 빌더는 다음과 같습니다
는public class BlurBuilder {
private static final float BITMAP_SCALE = 1f;
private static final float BLUR_RADIUS = 25f;
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);
/// compress bitmap here
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;
}
public static Bitmap blur(Context ctx, Bitmap image, float scale, float radius) {
int width = Math.round(image.getWidth() * scale);
int height = Math.round(image.getHeight() * 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(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;
}
}
드로어 블 코드를 게시 할 수 있습니까? –
요청하신대로 @KaranMer 게시물을 편집했습니다. – MichaelStoddart
당신은 이것을 위해 드로어 블 리소스를 사용하지 않으십니까? –