(android)如何使每个列表项模糊?

时间:2016-12-19 13:12:26

标签: android android-recyclerview

我正在使用此库来模糊视图(https://github.com/Dimezis/BlurView/blob/master/app/src/main/res/values/colors.xml)。

该库具有custsom视图,即'BlurView',即使背景图像发生变化,它也会动态模糊所有底层视图。它工作得很好。

我想为我的RecyclerView实现它,以便每个项目的背景可以模糊活动的背景。 但结果是这样的: enter image description here

我认为这个库拍摄了应用程序屏幕的快照并模糊了它。您可以看到工具栏完全模糊。 我希望这种模糊效果是动态的,这样当用户向上和向下滚动时,它可以实时模糊背景。它作为单个视图工作正常,但不作为列表项。

这是我的代码。

MainActivity.java

psql -h localhost -U user postgredb -c "select updateValue('someValue');"

PlanListAdapter.java

ListView listView = (ListView) findViewById(R.id.listview);
    PlanListAdapter adapter = new PlanListAdapter(this, getWindow().getDecorView(),new String[]{"Cookie", "Pie", "Banana split", "Peanut butter"});
    listView.setAdapter(adapter);

2 个答案:

答案 0 :(得分:3)

我是开发这个库的人。 我尝试重现这个错误,但是使用RecyclerView设置,我认为如果它在列表中,BlurView无法在屏幕上获得正确的位置。

你实际上可以在Github上解决问题,我会尽力在最近的时间解决这个问题。我相信使用View.getLocationOnScreen()

的类似案例应该有一个解决方法

修改 我已经将BlurView更新到1.3.0版本,修复了你的情况。 现在相对于rootView正确计算位置。

答案 1 :(得分:1)

所有模糊库都使用Android的Renderscript库,这对于某些Android手机来说有点问题(无论他们的Android版本如何)

以下是您可能遇到的运行时异常示例:

android.support.v8.renderscript.RSRuntimeException
SourceFile line 100 in BlurringView.a()
Error loading libRSSupport library

由于这是本机库,因此无法处理这些错误。我甚至在三星Galaxy的某些型号上遇到了这个错误。所以要注意这一点,如果你不需要,不要使用模糊库。

以下是有关该主题的更多信息:

Android - Renderscript Support Library - Error loading RS jni library

如果您真的想在视图上使用模糊,可以查看此库。如果您需要更多帮助,我可以使用此库向您发送我的示例代码。

https://developers.500px.com/a-blurring-view-for-android-7f33d41a047d#.nnl0sxpoz