Android 库模糊不工作

Android Libs Blurry Not Working

我使用 https://github.com/wasabeef/Blurry 库。

Onclick 中,以下代码有效。

private boolean blurred = false;

if (blurred) {
      Blurry.delete((ViewGroup) findViewById(R.id.content));
    } else {
      long startMs = System.currentTimeMillis();
      Blurry.with(MainActivity.this)
          .radius(25)
          .sampling(2)
          .async()
          .animate(500)
          .onto((ViewGroup) findViewById(R.id.content));
    }
blurred = !blurred;

但是当我在OnCreate中添加以下代码时,它不起作用。

Blurry.with(MainActivity.this)
      .radius(25)
      .sampling(2)
      .async()
      .animate(500)
      .onto((ViewGroup) findViewById(R.id.content));

您的图书馆使用 view size

  factor.width = target.getMeasuredWidth();
  factor.height = target.getMeasuredHeight();

当你调用它的时候。在 onCreate 中,您的视图尚未创建。例如,您应该将其移动到 onWindowFocusChanged(boolean hasFocus) 或使用 this link

for3st 的回答中的任何建议