PopupWindow自定义类
来源:互联网 发布:js 延时执行函数 编辑:程序博客网 时间:2024/04/27 15:49
public class PopupWindow extends PopupWindow{ private View conentView; private ListView popLv; private Window window; private WindowManager.LayoutParams layoutParams; private Activity context; private int type=0; public PopupWindow(final Activity context) { this.context=context; LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); conentView = inflater.inflate(R.layout.activity_popupwindow_list, null); //屏幕的宽和高 int height = context.getWindowManager().getDefaultDisplay().getHeight(); int width = context.getWindowManager().getDefaultDisplay().getWidth(); // 设置SelectPicPopupWindow的View this.setContentView(conentView); // 设置SelectPicPopupWindow弹出窗体的宽 this.setWidth(width / 2 -80); // 设置SelectPicPopupWindow弹出窗体的高 this.setHeight(RelativeLayout.LayoutParams.WRAP_CONTENT); // 设置SelectPicPopupWindow弹出窗体可点击 this.setFocusable(true); this.setOutsideTouchable(true); // 刷新状态 this.update(); // 实例化一个ColorDrawable颜色为半透明 ColorDrawable dw = new ColorDrawable(/*context.getResources().getColor(R.color.white)*/0000000000); // 点back键和其他地方使其消失,设置了这个才能触发OnDismisslistener ,设置其他控件变化等操作 this.setBackgroundDrawable(dw); //设置窗口的透明度 lp =context.getWindow().getAttributes(); lp.alpha=0.7f;//0.0为黑色,1.0透明 context.getWindow().setAttributes(lp); //设置pop隐藏时背景变成透明 this.setOnDismissListener(new poponDismissListener()); popLv= (ListView) conentView.findViewById(R.id. lv); imageList.add(R.mipmap.ic); textViewList.add("111"); imageList.add(R.mipmap.ic); textViewList.add("2222"); popLv.setAdapter(new PopupWindowAdapter(context,imageList,textViewList)); popLv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (position==0){ PopupWindow.this.dismiss(); }else if (position==1){ context.startActivity(new Intent(UIUtils.getContext(), XXX.class)); PopupWindow.this.dismiss(); lp.alpha=1.0f; context.getWindow().setAttributes(lp); } } }); } WindowManager.LayoutParams lp; //调用此方法即可parent是显示在那个控件下 public void showPopupWindow(View parent) { if (!this.isShowing()) { this.showAsDropDown(parent, parent.getLayoutParams().width / 2, 10); } else { this.dismiss(); context.getWindow().setAttributes(lp); } } class PopupWindowAdapter extends BaseAdapter { private Context context; private List<Integer> imageList; private List<String> textViewList; PopupWindowAdapter(Context context,List<Integer> imageList,List<String> textViewList){ this.context=context; this.imageList=imageList; this.textViewList=textViewList; } @Override public int getCount() { return imageList.size(); } @Override public Object getItem(int position) { return position; } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHoldr viewHoldr; if (convertView==null){ viewHoldr=new ViewHoldr(); convertView= LayoutInflater.from(context).inflate(R.layout.item_ popupwindow,null); viewHoldr.popImage= (ImageView) convertView.findViewById(R.id.pop _image); viewHoldr.popTv= (TextView) convertView.findViewById(R.id.pop_tv); convertView.setTag(viewHoldr); }else{ viewHoldr = (ViewHoldr)convertView.getTag(); } viewHoldr.popImage.setImageResource(imageList.get(position)); viewHoldr.popTv.setText(textViewList.get(position)); return convertView; } class ViewHoldr{ private ImageView popImage; private TextView popTv; } }}
0 0
- PopupWindow自定义类
- 自定义PopupWindow
- 自定义popupWindow
- 自定义PopupWindow
- 自定义PopupWindow
- PopupWindow自定义
- 自定义popupWindow
- popupwindow进阶--自定义menu
- 自定义PopupWindow动画效果
- android 自定义PopupWindow
- 自定义popupWindow显示位置
- android自定义一个PopupWindow
- PopupWindow自定义位置显示
- Android-自定义PopupWindow
- Android-自定义PopupWindow
- 5、Android-自定义PopupWindow
- 自定义控件----popupWindow
- 自定义PopupWindow+BaseAdapter+Anim
- ThreadLocal
- UML类图关系(泛化 、继承、实现、依赖、关联、聚合、组合)-转
- 怎么用NSMutableArray存储CGPoint,CGSize,CGRect,CGAffineTransform,UIEdgeInsets,UIOffset
- 过滤器(Filter)、拦截器(Interceptor)、监听器(Listener)
- Java中OutOfMemoryError
- PopupWindow自定义类
- WM_CLOSE WM_DESTROY WM_QUIT 区别
- 快捷操作方式
- 注解Annotation学习基础篇
- Elasticsearch2.3.4集群安装指南
- 【从零开始写一个简单的ImageLoader框架】MyImageLoader代码简介
- 11.其他复杂数据类型
- 源码分析-java-Vector、Stack-与ArrayList的相关性
- GCC 编译使用动态链接库