有没有更好的方法模糊一个 popup window 的背景

2018-02-10 19:32:34 +08:00
 Jimjay

第一先想到的肯定都是在 popup window 出来之前先截屏,然后模糊这个 bitmap,最后把它设成 popup 的背景。

但是在我的项目里,popup 是由一个 recyclerview 在 fragment 里 item tiggered 的。 理所当然, 这个 item 的回调方法是在这个 recyclerview 的 adapter 里,code like this

item.setOnClickListener(new OnClickListener){
    // capture the screen at this moment
    // trigger the popup window, and set the blurred bitmap to the background of         // the popup
    }

重点是 capture screen 那一 part 需要 activity 的引用,不然 get 不到 decor view。但是项目设计用的是 mvvm 模式,adapter 属于 view model 部分, 不能持有 activiy 引用,用了 databinding 框架,code like this

@BindingAdapter("bind:data")
public static void setData(RecyclerView recyclerView, List<ItemData> data){
    if (data != null) {
        recyclerView.setLayoutManager(new LinearLayoutManager(recyclerView.getContext(), LinearLayoutManager.HORIZONTAL, false));
        recyclerView.setAdapter(new ItemsAdapter(recyclerView.getContext(), data));
    }

所以 adapter 拿不到 activity 引用, 所以想问大神, 有什么办法模糊 popup 背景?

Note that: 重写 adapter 传入 activity,只能算一个折中办法

1114 次点击
所在节点    问与答
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/430047

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX