码迷,mamicode.com
首页 > 移动开发 > 详细

Android Popup Window 居于控件上方突出显示

时间:2015-12-22 19:06:12      阅读:231      评论:0      收藏:0      [点我收藏+]

标签:

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);
    }

}

 

Android Popup Window 居于控件上方突出显示

标签:

原文地址:http://www.cnblogs.com/niray/p/5067464.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!