您的位置:首页 > 运维架构

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

2016-04-15 18:00 375 查看
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();
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: