PopupWindow学习总结
来源:互联网 发布:海牛多多运营软件 编辑:程序博客网 时间:2024/05/19 17:51
经过一段时间的学习,了解了PopupWindow的基本用法,如下:
1、为PopupWindow的view布局,通过LayoutInflator获取布局的view.如:
LayoutInflaterinflater=(LayoutInflater)this.anchor.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ViewtextEntryView=inflater.inflate(R.layout.paopao_alert_dialog,null);
2、显示位置,可以有很多方式设置显示方式
pop.showAtLocation(findViewById(R.id.ll2),Gravity.LEFT,0,-90);
3、进出场动画
pop.setAnimationStyle(R.style.PopupAnimation);
4、点击PopupWindow区域外部,PopupWindow消失
this.window=newPopupWindow(anchor.getContext());
this.window.setTouchInterceptor(newOnTouchListener(){
@Override
publicbooleanonTouch(Viewv,MotionEventevent){
if(event.getAction()==MotionEvent.ACTION_OUTSIDE){
BetterPopupWindow.this.window.dismiss();
returntrue;
}
returnfalse;
}
});
教训:
1、PopuWindow的大小由下面代码控制;
newPopupWindow(view,ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
2、popuWindow.showAsDropDown(v);方法是将PopuWindow显示在Viewv的左下方;
3、需要顺利让PopUpWindowdimiss(即点击PopuWindow之外的地方此或者back键PopuWindow会消失);PopUpWindow的背景不能为空。必须在popuWindow.showAsDropDown(v);或者其它的显示PopuWindow方法之前设置它的背景不为空:如下面两行代码:
ColorDrawablecd=newColorDrawable(-0000);
popuWindow.setBackgroundDrawable(cd);
popuWindow.showAsDropDown(v);
注意这里设置背景并不会覆盖xml文件定义的背景。
4、当有popuWindow.setFocusable(false);的时候,说明PopuWindow不能获得焦点,即使设置设置了背景不为空也不能点击外面消失,只能由dismiss()消失,但是外面的View的事件还是可以触发,back键也可以顺利dismiss掉。当设置为popuWindow.setFocusable(true);的时候,加上下面两行设置背景代码,点击外面和Back键才会消失。
5、//这里设置显示PopuWi
- PopupWindow学习总结
- PopupWindow学习总结
- PopupWindow总结
- PopupWindow总结
- PopupWindow学习
- PopupWindow学习
- PopupWindow学习
- PopupWindow使用总结:
- 使用PopupWindow总结
- Android总结之PopupWindow
- PopupWindow使用总结
- Android PopupWindow使用总结
- Android PopupWindow使用总结
- 下拉菜单 spinner ,popupwindow, 自定义popupwindow总结
- 学习笔记 popupwindow
- PopupWindow学习大全
- android学习之popupWindow
- Android学习之PopupWindow
- adobe reader 菜单栏显示不出字
- 如何禁用 UITableView 的高亮选取?
- Android中notifyDataSetInvalidated()和notifyDataSetChanged()有什么区别
- 选择排序:直接选择排序,堆排序
- Js 回车换行处理的办法
- PopupWindow学习总结
- C# WinForm开发系列 - 文章索引
- 设计模式--策略模式
- jQuery实例--Ajax信息的增删改查等操作
- android style(样式)和theme(主题)设置
- Linux进程间通信(二): 信号(下)
- request.getRequestDispatcher("/PlacardAction.do?method=toView").forward(request, response)
- joim之android串口通信测试
- 搭建Android界面工具资料