【发布时间】:2017-03-21 07:14:09
【问题描述】:
我想复制 RecyclerView 的项目中的文本内容,所以我在 TextView 上设置了一个 OnLongClickListener,同时它会显示一个包含复制按钮的 PopupWindow。
我的问题是,当 PopupWindow 显示并滚动 RecycleView 时我仍在触摸 RecycleView 时,RecycleView 意外滚动。
我需要的是,如果 PopupWindow 已经显示,无论我是否还在触摸 RecyclerView,PopupWindow 都应该有焦点,除非 PopupWindow 被关闭,否则我不能做其他事情。
我初始化一个 PopupWindow 代码:
mPopupWindow = new PopupWindow(context);
mPopupWindow.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
mPopupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
View contentView = LayoutInflater.from(context).inflate(R.layout.comment_popup_layout, null);
mPopupWindow.setContentView(contentView);
mPopupWindow.setOutsideTouchable(true);
mPopupWindow.setTouchable(true);
mPopupWindow.setFocusable(true);
mPopupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
我使用showAsDropDown(View anchor, int xoff, int yoff)的方法来显示窗口。
在我搜索谷歌很长时间之后需要一些帮助。
谢谢!
【问题讨论】:
-
mPopupWindow.setOutsideTouchable(false);使用这个
-
mPopupWindow.setOutsideTouchable(true);使其为假 mPopupWindow.setOutsideTouchable(false);禁用背景元素触摸事件
-
@quicklearner 我试过了,但我仍然可以滚动我的 RecyclerView
-
你可以在这里发布你的适配器类以便我可以帮助你吗?
-
@quicklearner 这是一个很长的代码。但是
itemHold.setCommentClick(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { mCommentPopDialog.show(v, item.getGroupId(), item.getContent(), item.getUserName()); return true; } });
标签: android android-recyclerview popupwindow android-popupwindow