Blurry
Blurry copied to clipboard
Blurry not working in onCreate?
Hi wasabeef, i really like blurry library, but i had a problem with this. When i set Blurry(..) in OnCreate method then it not working ?
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); getId();//get id of rela_Background init(); Blurry.with(context) .radius(25) .sampling(6) .async() .animate(500) .onto(rela_Background); }
How to blur "rela_Background" when open app .
try this:
yourView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Blurry.with(context)
.radius(25)
.sampling(6)
.async()
.animate(500)
.onto(rela_Background);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
searchView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
else
searchView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
});
if not work, try to call
Blurry.with(context)
.radius(25)
.sampling(6)
.async()
.animate(500)
.onto(rela_Background);
two times. I don't know why but Blurry works to me only after second call.
ohh. this work !! thanks . me too " I don't know why but Blurry works to me only after second call. " :)
You can also do it this way:
yourView.post(new Runnable() {
@Override
public void run() {
Blurry.with(context)
.radius(25)
.sampling(6)
.async()
.animate(500)
.onto(rela_Background);
}
});
It has the same effect as 15555's method.
My onCreate is below:
final LinearLayout root = (LinearLayout) findViewById(R.id.login_view);
root.post(new Runnable() {
@Override
public void run() {
Blurry.with(LoginActivity.this)
.radius(25)
.sampling(2)
.async()
.animate(500)
.onto((ViewGroup) root);
}
});
Blurry is still not working for me and if i call it twice as mentioned above, i get the below error:
java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@4a28ec at android.graphics.Canvas.throwIfCannotDraw(Canvas.java:1270) at android.graphics.Canvas.drawBitmap(Canvas.java:1325) at jp.wasabeef.blurry.internal.Blur.of(Blur.java:63) at jp.wasabeef.blurry.internal.BlurTask$1.run(BlurTask.java:61) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) at java.lang.Thread.run(Thread.java:818)
So I'm adding the blur within onBindViewHolder()
on my recycler view adapter. Calling it twice didn't work, but post()
does. Thanks @Pkmmte!