如何让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();
}
}
}
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();
}
}
}
相关文章推荐
- Linux下驱动调试方法
- Tomcat之虚拟主机配置以及web应用配置
- linux inotify+rsync
- Android官方MVP架构示例项目解析
- Tomcat的JVM设置和连接数设置
- 03搭建docker私有仓库
- Codeigniter设置伪静态出现404错误
- docker保存对容器的修改
- linux 版本号中EL代表enterprise linux
- Linux Shell变量
- 关于 dedecms 网站程序及数据库完美迁移的教程
- opencv静态库,链接出错,error lnk 2005 (vs2008)
- CentOS7上GitHub/GitLab多帐号管理SSH Key
- OpenCV中寻找轮廓函数cvFindContours的使用说明以及序列cvSeq的用法说明
- CentOS安装ReviewBoard记录
- 系统镜像盘ISO的制作--基于tinycorelinux
- linux移植时出现 Unable to find the ncurses libraries ....解决办法
- popupwindow在顶部或底部出现,背景变暗
- popToViewController用法(亲测可用)
- Linux