控件.set Listener(new View. Listener() {
@Override
public void (View v) {
showPopupWindow(v);
int[] location = new int[2];
v.getLocationOnScreen(location);
int x = location[0]-myPopupWindow1.getWidth()+(map_right_second.getWidth()/2); //把下面第一个0换成x就会显示在控件x方向中间部分
int y = location[1]-myPopupWindow1.getHeight()+(map_right_second.getHeight()/2);//把下面第二个0换成y就会显示在控件y方向中间部分
myPopupWindow2.showAtLocation(v, Gravity.CENTER, 0, 0);//(控件,相对屏幕的位置,距离控件x方向的距离,距离控件y方向的距离)
}
});
//popwindow
private PopupWindow myPopupWindow;
private View infoView;
public void showPopupWindow(View view){
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int width = dm.widthPixels;//屏幕宽度
infoView = LayoutInflater.from(TongjiActivity.this).inflate(R.layout.popwindow_view,null);//布局文件
myPopupWindow = new PopupWindow(infoView, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT, true);//(布局文件(View),popwindow宽,popwindow高,指定PopupWindow能否获得焦点)
myPopupWindow.setContentView(infoView);
myPopupWindow.setBackgroundDrawable(getDrawable());//设置背景透明以便点击外部消失
myPopupWindow.setOutsideTouchable(true);//点击外部收起
myPopupWindow.setFocusable(true);//设置焦点生效
myPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
@Override
public void onDismiss() {
}
});
final TimePicker mTimePicker = (TimePicker) infoView.findViewById(R.id.time_picker);
final DatePicker mDatePicker = (DatePicker) infoView.findViewById(R.id.date_picker);
mTimePicker.setIs24HourView(true);
final Button tv_sure_list_datecheck = (Button) infoView.findViewById(R.id.btn_ok);
tv_sure_list_datecheck.set Listener(new View. Listener() {
@Override
public void (View v) {
}
});
// 显示PopupWindow,其中: // 第一个参数是PopupWindow的锚点,第二和第三个参数分别是PopupWindow相对锚点的x、y偏移 //window.showAsDropDown(anchor, xoff, yoff);
}
//背景
private Drawable getDrawable(){
ShapeDrawable bgdrawable =new ShapeDrawable(new OvalShape());
bgdrawable.getPaint().setColor(TongjiActivity.this.getResources().getColor(R.color.color_half_translate));
return bgdrawable;
}
//背景颜色
<color name=\"color_half_translate\">#90000000</color>
继续阅读与本文标签相同的文章
下一篇 :
设计者模式-单例模式和多例的区别
-
怎样彻底删除手机中的微信记录简单快捷同步登陆不被发现一步到位!
2026-05-18栏目: 教程
-
双面明星哈弗F7x 一面引领潮派一面掌控智能
2026-05-18栏目: 教程
-
曙光携手北邮,以“人工智能”为“校园安全”代言
2026-05-18栏目: 教程
-
Hitachi Vantara推出AI驱动的数据中心运营解决方案
2026-05-18栏目: 教程
-
湖北发力“5G”:天时地利人和
2026-05-18栏目: 教程
