自己使用popupwindow时遇到的
来源:互联网 发布:美国新纳粹知乎 编辑:程序博客网 时间:2024/06/03 09:08
/**
02
* 初始化rightPopupWindow
03
*/
04
private
PopupWindow initPopupWindow() {
05
06
LayoutInflater inflater = LayoutInflater.from(
this
);
07
View popView = inflater.inflate(R.layout.popupwindow_content,
null
);
08
TextView item = (TextView) popView.findViewById(R.id.text_item);
09
10
// 创建PopupWindow
11
final
PopupWindow popupWindow = createPopupWindow(popView);
12
13
popView.setOnTouchListener(
new
View.OnTouchListener() {
14
@Override
15
public
boolean
onTouch(View v, MotionEvent event) {
16
if
(rightPop !=
null
&& rightPop.isShowing()) {
17
popupWindow.dismiss();
18
}
19
return
true
;
20
}
21
});
22
23
item.setOnClickListener(
new
View.OnClickListener() {
24
@Override
25
public
void
onClick(View v) {
26
popupWindow.dismiss();
27
// ...
28
}
29
});
30
31
return
popupWindow;
32
}
如何在PopupWindow之外的区域点击后,PopupWindow会消失呢。
看下实现的相关代码:popupWindow.setBackgroundDrawable(new BitmapDrawable());
popupWindow.setFocusable(true);
popupWindow.setTouchable(true);
popupWindow.setOutsideTouchable(true);
popupWindow.showAsDropDown(button);
ok,这样做没问题的。点击 PopupWindow之外的区域后, PopupWindow会消失 。
(1)我把第一行注释掉呢:
// popupWindow.setBackgroundDrawable(new BitmapDrawable());
popupWindow.setFocusable(true);
popupWindow.setTouchable(true);popupWindow.setOutsideTouchable(true);
popupWindow.showAsDropDown(button);
这个时候会发现点击PopupWindow之外的区域后, PopupWindow不会消失。
因此在显示popupWindow 之前我们必须要setBackgroundDrawable来进行设置哦。
(2)我把setOutsideTouchable 放在showAsDropDown 后面设置呢:
popupWindow.setBackgroundDrawable(new BitmapDrawable());
popupWindow.setFocusable(true);
popupWindow.setTouchable(true);
popupWindow.showAsDropDown(button);
popupWindow.setOutsideTouchable(true);
这个时候会发现点击 PopupWindow之外的区域后, PopupWindow会消失 。
(3)然后我把setFocusable ,setTouchable ,setOutsideTouchable 放在showAsDropDown 后面呢
popupWindow.setBackgroundDrawable(new BitmapDrawable());
popupWindow.showAsDropDown(button);
popupWindow.setFocusable(true);
popupWindow.setTouchable(true);
popupWindow.setOutsideTouchable(true);
这个时候会发现点击 PopupWindow之外的区域后, PopupWindow不会消失。
在界面使用showAsDropDown或者showAtLocation调整popupwindow的位置的时候,必须考虑popupwindow自身的宽度因素,否则在适配时popupwindow在主界面的位置难以调整
0 0
- 自己使用popupwindow时遇到的
- 使用popupwindow时遇到的坑
- Popupwindow遇到的问题
- 关于使用PopupWindow的遇到的一些小问题
- PopupWindow的使用细节以及今天遇到的小问题
- android:使用popupwindow遇到的那些事(一)
- cocopod自己使用遇到的一些问题
- $("#id").ajaxSubmit()使用自己遇到的问题
- Android PopupWindow的使用
- Android PopupWindow的使用
- Android PopupWindow的使用!!!
- 关于popupWindow的使用
- PopupWindow的使用
- PopupWindow的使用例子
- PopupWindow的使用
- popupWindow的使用心得
- PopupWindow的使用
- PopupWindow的使用
- 线程的优先级
- linux下安装apche的安装
- Linux学习,第二天(文件权限),学习笔记
- 对象序列化
- dijkstra算法
- 自己使用popupwindow时遇到的
- VARIANT的简便介绍
- jhgjgjhgjkhhghgfjhfgdgj
- RPG游戏战斗场景的设计
- 算法竞赛入门经典 5.1 字符串总结
- POJ2456 Aggressive cows
- 开源项目之Android async-http
- hdu 2647 Rewaed(拓扑排序+链式前向星)
- 旧版SneakyInput升级2.0+改动