最近用7.0的android手機(jī)測試項目,發(fā)現(xiàn)popwindow的showAsDropDown失效了,
不過最終找到了兩種解決方案:
1弦聂、重寫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);
}
2心赶、使用showAtLocation方法:
if (Build.VERSION.SDK_INT >= 24) {
int[] point = new int[2];
v.getLocationInWindow(point);
mPopWindow.showAtLocation(((Activity) mContext).getWindow().getDecorView(), Gravity.NO_GRAVITY, 0, point[1] + v.getHeight());
} else {
mPopWindow.showAsDropDown(v);
}