android中popupwindow怎么把一个页面做个弹窗

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了android中popupwindow怎么把一个页面做个弹窗相关的知识,希望对你有一定的参考价值。

参考技术A android PopupWindow怎么合理控制弹出位置123456789101112131415161718192021222324252627282930private void showPopupWindow(View parent) if (popupWindow == null) LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); view = layoutInflater.inflate(R.layout.group_list, null); lv_group = (ListView) view.findViewById(R.id.lvGroup); Collections.reverse(groups); GroupAdapter groupAdapter = new GroupAdapter(this, groups); lv_group.setAdapter(groupAdapter); popupWindow = new PopupWindow(view, 200, 220); popupWindow.setFocusable(true); popupWindow.setOutsideTouchable(true); //设置点击屏幕其它地方弹出框消失 popupWindow.setBackgroundDrawable(new BitmapDrawable()); WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE); int xPos = -popupWindow.getWidth() / 2 + getCustomTitle().getCenter().getWidth() / 2; popupWindow.showAsDropDown(parent, xPos, 4); lv_group.setOnItemClickListener(new OnItemClickListener() @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) loadNew(((StringItem)(groups.get(position))).getId()); if (popupWindow != null) popupWindow.dismiss(); ); 只需要设置proupwindows的setOutsideTouchable属性即可。以下为示例代码:window.showAtLocation(parent, Gravity.RIGHT Gravity.BOTTOM, 10,10);//显示位置第一个参数指定PopupWindow的锚点view,即依附在哪个view上。第二个参数指定起始点第三个参数设置以起始点的右下角为原点,向左、上各偏移的像素。自己看下API

以上是关于android中popupwindow怎么把一个页面做个弹窗的主要内容,如果未能解决你的问题,请参考以下文章

android中介绍popupWindow,说它是阻塞线程式的alertDialog,这个阻塞线程该怎么理解呢?

android 怎么自定popupwindow设置高度无反应

怎么设置android中的popupwindow进入和退出的动画

怎么设置android中的popupwindow进入和退出的动画

Android PopupWindow怎么合理控制弹出位置(showAtLocation)

android 怎么实现点击屏幕其他地方popupwindow消失