【每天积累一点点】将PopupWindow显示在指定位置

来源:互联网 发布:有关修车的软件 编辑:程序博客网 时间:2024/05/17 21:31
//以想在控件tvMl的右下角显示PopupWindow为例(popupWindow的右上角在tvMl的右下角)            View popPhotoView = LayoutInflater.from(this).inflate(R.layout.popup_ml_choose, null);            mlWindow = new PopupWindow(popPhotoView, Utils.dip2px(this, 132), Utils.dip2px(this, 176), true);            mlWindow.setBackgroundDrawable(new BitmapDrawable());            mlWindow.setAnimationStyle(R.style.mypopwindow_anim_style);            mlWindow.setOutsideTouchable(true);            //获取tvMl在屏幕中的位置,其中location[0]是tvMl左上角的x位置,location[1]是tvMl左上角y轴的位置            int[] location = new int[2];            tvMl.getLocationOnScreen(location);//            showAtLocation(View parent, int gravity, int x, int y),其中x,y参数是PopupWindow的左上角的(x,y)坐标            mlWindow.showAtLocation(tvMl, Gravity.NO_GRAVITY, location[0] + tvMl.getWidth() - mlWindow.getWidth(), location[1] + tvMl.getHeight());

阅读全文
0 0
原创粉丝点击