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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yinzhijiezhan/article/details/77748455
//以想在控件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());

猜你喜欢

转载自blog.csdn.net/yinzhijiezhan/article/details/77748455
今日推荐