public class TestPopupWindowActivity extends PopupWindow {
    Activity context;

    public TestPopupWindowActivity(Activity context, View v) {
        super(context);
        this.context = context;
        RelativeLayout mContentView = new RelativeLayout(context);
        RelativeLayout.LayoutParams lpBg = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        mContentView.setLayoutParams(lpBg);

        ImageView ivBg = new ImageView(context);
        ivBg.setImageResource(R.mipmap.icon_alipay);

        mContentView.addView(ivBg);

        mContentView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);

        this.setContentView(mContentView);
        this.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        this.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
        this.setFocusable(true);
        this.setBackgroundDrawable(new ColorDrawable(Color.GRAY));
        this.setOutsideTouchable(true);
        this.update();
        int popupWidth = mContentView.getMeasuredWidth();
        int popupHeight = mContentView.getMeasuredHeight();
        int[] location = new int[2];
        v.getLocationOnScreen(location);
        showAtLocation(v, Gravity.NO_GRAVITY, location[0] + v.getWidth() / 2 - popupWidth / 2, location[1] - popupHeight);
    }

}

 

相关文章:

  • 2021-09-11
  • 2021-12-28
  • 2021-06-16
  • 2021-11-18
  • 2022-12-23
  • 2021-11-09
  • 2022-12-23
  • 2021-09-30
猜你喜欢
  • 2021-12-24
  • 2022-02-08
  • 2022-12-23
  • 2022-02-11
  • 2022-03-02
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案