[问题解决]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系统下都没有类似问题。
问题解决
重写showAsDropDown(view)
,如下:
@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);
}