PopWindow使用总结

谈起popwindow的显示问题,显示在view上方:

    public class ImChatItemPopWindow extends PopupWindow{
    private Context mContext;
    private View mParentView;
    private View convertView;
     public ImChatItemPopWindow(Context context)
    {
        super(context);
        mContext = context;
        convertView = View.inflate(context, R.layout.im_chat_item_popup, null);
        this.setContentView(convertView);
        setWidth(WindowManager.LayoutParams.WRAP_CONTENT);
        setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
        this.setOutsideTouchable(true);
        /** 为其设置背景,使得其内外焦点都可以获得 */
        this.setBackgroundDrawable(new ColorDrawable());
        this.setFocusable(true);
      }
      public void showPopWindow(View v){
        int[] location = new int[2];
        v.getLocationOnScreen(location);
        View popupView = LayoutInflater.from(UiApplication.getCurrentContext()).inflate(R.layout.im_chat_item_popup, null);
        PopupWindow popupWindow = new PopupWindow(popupView, ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT, true);
        popupWindow.setBackgroundDrawable(new BitmapDrawable());
        popupView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
        int popupWidth = popupView.getMeasuredWidth();
        int popupHeight =  popupView.getMeasuredHeight();

        popupWindow.showAtLocation(v, Gravity.NO_GRAVITY, location[0],//(location[0]+v.getWidth()/2)-popupWidth/2,
                location[1]-popupHeight);
        }   
}            

特别注意高度处 是减去 popupHeight,不是parentView.getHeight(),网上很多事减去 popwindow.getHeight(),在这里即为 减去this.getHeight(),小编试了一下,效果不正常(-this.getHeight())。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值