android 华为 showAsDropDown位置错乱
华为7.0会出现位置错乱,网上有两种方法。
第一种:使用showAtLocation方法
if (Build.VERSION.SDK_INT != 24) { brandPopup.showAsDropDown(parent);
} else { // 获取控件的位置,安卓系统>7.0 int[] location = new int[2]; parent.getLocationOnScreen(location); brandPopup.showAtLocation(parent, Gravity.NO_GRAVITY, location[0], location[1] + parent.getHeight());
}
第二种:
popwindow重写showAsDropDown方法。
@Overridepublic void showAsDropDown(View anchor) {if (Build.VERSION.SDK_INT == 24) {Rect rect = new Rect();anchor.getGlobalVisibleRect(rect);int h = anchor.getResources().getDisplayMetrics().heightPixels - rect.bottom;setHeight(h);}super.showAsDropDown(anchor);}
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
