popupwindow的用法

来源:互联网 发布:java编译手机模拟器 编辑:程序博客网 时间:2024/06/04 19:10
private void initiatePopupWindow() {        try {            //We need to get the instance of the LayoutInflater, use the context of this activity            LayoutInflater inflater = (LayoutInflater)                    getSystemService(Context.LAYOUT_INFLATER_SERVICE);            //Inflate the view from a predefined XML layout            View layout = inflater.inflate(R.layout.popup,null);            // create a 300px width and 470px height PopupWindow//            pw = new PopupWindow(layout,800,600);            pw = new PopupWindow(layout);            //设置PopupWindow弹出窗体的宽            pw.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);            //设置PopupWindow弹出窗体的高            pw.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);            //让PopupWindow聚焦的方式,让其它子控件获取不到焦点,从而解决点击事件透传的问题            pw.setFocusable(true);            //设置点击pw其他区域隐藏pw            pw.setOutsideTouchable(true);//                                    实例化一个ColorDrawable颜色为半透明            ColorDrawable dw = new ColorDrawable(0xb0000000);//            设置SelectPicPopupWindow弹出窗体的背景            pw.setBackgroundDrawable(dw);            //设置SelectPicPopupWindow弹出窗体动画效果            pw.setAnimationStyle(R.style.PwAnimation);            // display the popup in the center//            pw.showAtLocation(v, Gravity.BOTTOM, 0, 0);            RecyclerView rvShop = (RecyclerView) layout.findViewById(R.id.rv_shop);            TextView tvCancel = (TextView) layout.findViewById(R.id.tv_shop_cancel);            LinearLayoutManager layoutManager = new LinearLayoutManager(this);            MyMapAdapter adapter = new MyMapAdapter();            rvShop.setLayoutManager(layoutManager);            rvShop.setAdapter(adapter);            adapter.setOnMapItemClkListener(new OnMapItemClkListener() {                @Override                public void onMapClk(View v, int position) {                    Logger.d(this,"点击了地图");                    //集合中包含百度地图                    //跳转到百度地图                }            });            tvCancel.setOnClickListener(new View.OnClickListener() {                @Override                public void onClick(View v) {                    pw.dismiss();                }            });        } catch (Exception e) {            e.printStackTrace();        }    }
原创粉丝点击