首页 > 代码库 > 7.0手机后popupWindow 的showAtLocation()和showAsDropDown()

7.0手机后popupWindow 的showAtLocation()和showAsDropDown()

  手机系统7.0后用showAsDropDown()会位置异常,这是用showAtLocation()就好了。

if (Build.VERSION.SDK_INT < 24) {//在7.0之前
pw.showAsDropDown(ll_rank, 0, 0);//ll_rank是一个view,表示显示在下方
} else {
// 适配 android 7.0
int[] location = new int[2];
re_hotel_address.getLocationOnScreen(location);//re_hotel_address是一个view,表示显示在她的上方
int x = location[0];
int y = location[1];
pw.showAtLocation(re_hotel_address, Gravity.NO_GRAVITY, 0,y);
}

技术分享

 

7.0手机后popupWindow 的showAtLocation()和showAsDropDown()