手机系统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);
}
时间: 2024-12-15 20:35:21