美文网首页
android 华为 showAsDropDown位置错乱

android 华为 showAsDropDown位置错乱

作者: 菜鸟何时起飞 | 来源:发表于2020-07-06 15:13 被阅读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方法。

 @Override
    public 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);
    }

相关文章

网友评论

      本文标题:android 华为 showAsDropDown位置错乱

      本文链接:https://www.haomeiwen.com/subject/khowqktx.html