V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
Jimjay
V2EX  ›  问与答

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

  •  
  •   Jimjay · 2018-02-10 19:32:34 +08:00 · 1103 次点击
    这是一个创建于 2260 天前的主题,其中的信息可能已经有所发展或是发生改变。

    第一先想到的肯定都是在 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,只能算一个折中办法

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1005 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 22:54 · PVG 06:54 · LAX 15:54 · JFK 18:54
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.