[问题解决]Android7.0上PopupWindow的showAsDropDown位置问题

[问题解决]Android7.0上PopupWindow的showAsDropDown位置问题

/** * Created by diql on 2017/02/16. */

问题说明

个人popupWindow是用来展现listView的,近期在Android7.0手机上测试发现showAsDropDown(view)展现时发现会充满屏幕,而不是展现在view的下方,测试发如今7.0如下和7.1系统下都没有相似问题。css

问题解决

重写showAsDropDown(view),以下:java

@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);
    }
相关文章
相关标签/搜索