鉴于上一篇博客 为了灵活使用,在上一篇的基础上,再做一些封装
1.具体的封装如下:
/**封装的popwindow 弹框 * 1.showlocation 类型 * 2.动画效果 从下往上 * 3.布局不确定 * 4.背景透明可以传参 * 5.弹出动画可以传参 * 6.宽高 可以传参 * */ public void showPopListCommon(TextView textView,int Resid,int listviewid,int width,int height,int animationStyle,float bg) { if (sfPopupWindow != null && sfPopupWindow.isShowing()) { sfPopupWindow.dismiss(); backgroundAlpha(1f); } else { popView = LayoutInflater.from(this).inflate(Resid, null);//加载popwindow的布局 ListView listViewSort = (ListView) popView.findViewById(listviewid); setPopListView(listViewSort);//listview的配置 包含点击事件 listViewSort.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { if (sfPopupWindow != null && sfPopupWindow.isShowing()) { sfPopupWindow.dismiss(); backgroundAlpha(1f); } setPopListViewItemData(i); } }); //设置弹出popupWindow的宽高 sfPopupWindow = new SFPopupWindow(this); sfPopupWindow.setContentView(popView); /*int height = getResources().getDisplayMetrics().heightPixels * 1 / 3;*/ sfPopupWindow.setHeight(height);//设置高度 sfPopupWindow.setWidth(width);//设置宽度 sfPopupWindow.setAnimationStyle(animationStyle);//动画效果 R.style.AnimationPreview sfPopupWindow.setOnDismissListener(new poponDismissListener()); backgroundAlpha(bg); sfPopupWindow.update(); sfPopupWindow.setBackgroundDrawable(new BitmapDrawable());//去除黑边 sfPopupWindow.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED); sfPopupWindow.setTouchable(true); sfPopupWindow.setOutsideTouchable(true); sfPopupWindow.setFocusable(true); sfPopupWindow.showAtLocation(textView, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0); sfPopupWindow.setTouchInterceptor(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {//点击外部消失 sfPopupWindow.dismiss(); backgroundAlpha(1f); return true; } return false; } }); } }2.如果说 ,有一些通过的类型,如上述所示:
/**封装的popwindow 弹框 * 1.showlocation 类型 * 2.动画效果 从下往上 * 3.宽度占满全屏,高度为屏幕的三分之一 * */ public void showPopList(TextView textView) { int height = getResources().getDisplayMetrics().heightPixels * 1 / 3;//高度 int width = ViewGroup.LayoutParams.MATCH_PARENT;//宽度 int animonStyle = R.style.AnimationPreview; //动画效果 float bg = 0.6f;//背景透明度 showPopListCommon(textView, R.layout.pop_menulist_sort, R.id.menulist_sort, width, height, animonStyle, bg); }
3.在其他页面 可以调用 第二个方法 ,去写逻辑操作