相关疑难解决方法(0)

触摸外面后避免PopupWindow被解雇

我想使用具有以下行为/功能的PopupWindow:

  • 它是可聚焦的(例如,按钮内有交互式控件)
  • '弹出窗口'下的视图'必须正确消耗弹出窗口外的触摸
  • ..但是弹出窗口即使在外面点击也必须留在屏幕上

我发现了一些关于PopupWindow的帖子,但没有人问过如何处理这种情况.

我想我尝试了setOutsideTouchable(),setFocusable(),setTouchable()的所有可能组合,但我陷入困境.Popup正确处理它的点击,但是当它在外面触摸时它总是被解雇.

我目前的代码是:

View.OnTouchListener customPopUpTouchListenr = new View.OnTouchListener(){

    @Override
    public boolean onTouch(View arg0, MotionEvent arg1) {
        Log.d("POPUP", "Touch false");
        return false;
    }

};


LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout layout= (LinearLayout)inflater.inflate(R.layout.insert_point_dialog, null);
PopupWindow pw = new PopupWindow(layout,400,200,true);
pw.setOutsideTouchable(true);
pw.setTouchable(true);
pw.setBackgroundDrawable(new BitmapDrawable());
pw.setTouchInterceptor(customPopUpTouchListenr);
pw.showAtLocation(frameLayout, Gravity.BOTTOM, 0, 0);
Run Code Online (Sandbox Code Playgroud)

我的总体目标是创建一个浮动窗口,其行为类似于gimp等软件中的"工具调色板":内部有一些控件,保持在顶部直到被"X"按钮关闭,并允许与其外部的控件进行交互.也许有更好的方法来做到这一点,而不是PopupWindow?但我仍然没有找到更合适的控制.

android

13
推荐指数
4
解决办法
2万
查看次数

标签 统计

android ×1