如何让popuwindow在指定的位置显示

private void showPopuWindow() {

if (mypopuwindow == null) {

mypopuwindow = new Memberpurchasewindow(MainActivity.this);

}

mypopuwindow.showPopupWindow(radioButton[1]);

}


public class Memberpurchasewindow extends PopupWindow {

public Activity context;


public Memberpurchasewindow(Activity context) {

this.context = context;

View defineview = View.inflate(context,

R.layout.memberpurchasewindow, null);

int h = context.getWindowManager().getDefaultDisplay().getHeight();  

        int w = context.getWindowManager().getDefaultDisplay().getWidth();  

        // 设置SelectPicPopupWindow的View  

        this.setContentView(defineview);  

        // 设置SelectPicPopupWindow弹出窗体的宽  

        this.setWidth(LayoutParams.WRAP_CONTENT);  

        // 设置SelectPicPopupWindow弹出窗体的高  

        this.setHeight(LayoutParams.WRAP_CONTENT);  

        // 设置SelectPicPopupWindow弹出窗体可点击  

        this.setFocusable(true);  

        this.setOutsideTouchable(true);  

        // 刷新状态  

        this.update();  

        // 实例化一个ColorDrawable颜色为半透明  

        ColorDrawable dw = new ColorDrawable(0000000000);  

        // 点back键和其他地方使其消失,设置了这个才能触发OnDismisslistener ,设置其他控件变化等操作  

        this.setBackgroundDrawable(dw);  

        // mPopupWindow.setAnimationStyle(android.R.style.Animation_Dialog);  

        // 设置SelectPicPopupWindow弹出窗体动画效果  

      //  this.setAnimationStyle(R.style.AnimationPreview);  

ImageView goldview = (ImageView) defineview

.findViewById(R.id.goldmember);

ImageView quickmeber = (ImageView) defineview

.findViewById(R.id.quickmember);

goldview.setOnClickListener(new OnClickListener() {//点击金牌会员的时候触发的事件


@Override

public void onClick(View v) {

if(LoginHelper.isLogin(MainActivity.this)){

Intent intent=new Intent(MainActivity.this,MemberPurcharse.class);

intent.putExtra("showUrl", "http://www.kxyaoshi.com/m/index.html?androidykl=1");

intent.putExtra("fromfirstpage", true);

startActivity(intent);

}else{

//TODO

Intent intent = new Intent(MainActivity.this,

LoginActivity.class);

intent.putExtra("onlyclose", true);

startActivityForResult(intent, PERSONALCENTER);

}


}

});

quickmeber.setOnClickListener(new OnClickListener() {//点击冲刺会员的时候触发的事件


@Override

public void onClick(View v) {

if(LoginHelper.isLogin(MainActivity.this)){

Intent intent=new Intent(MainActivity.this,MemberPurcharse.class);

intent.putExtra("showUrl", "http://www.kxyaoshi.com/wsprint/index.shtml?androidykl=1");

intent.putExtra("fromfirstpage", true);

startActivity(intent);

}else{

//TODO

Intent intent = new Intent(MainActivity.this,

LoginActivity.class);

intent.putExtra("onlyclose", true);

startActivityForResult(intent, PERSONALCENTER);

}


}


});


}


public void showPopupWindow(View parent) {

int[] location = new int[2];

int parentHeight=parent.getMeasuredHeight();

parent.getLocationOnScreen(location);

if (!this.isShowing()) {

int popupWidth = this.getWidth();

int popupHeight = this.getHeight();


this.showAtLocation(parent, Gravity.NO_GRAVITY,

(location[0] + parent.getWidth() / 2) - popupWidth / 2,

location[1] - parentHeight);

} else {

this.dismiss();

}

}

}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值