View view = LayoutInflater.
from(
this).inflate(R.layout.
xxx,
null);
popupWindow =
new PopupWindow(view, ViewGroup.LayoutParams.
MATCH_PARENT, ViewGroup.LayoutParams.
MATCH_PARENT,
true) {
@Override
public void showAsDropDown(View anchor) {
Class<?> popupwindow = PopupWindow.
class;
try {
Method m2 = popupwindow.getDeclaredMethod(
"computeGravity");
m2.setAccessible(
true);
int invoke = (
int) m2.invoke(
popupWindow);
int gravity = Gravity.
START | Gravity.
TOP;
if (invoke == gravity) {
Rect rect =
new Rect();
anchor.getGlobalVisibleRect(rect);
int h = anchor.getResources().getDisplayMetrics().
heightPixels - rect.
bottom;
setHeight(h);
}
}
catch (Exception e) {
e.printStackTrace();
}
super.showAsDropDown(anchor);
}
};
popupWindow.setBackgroundDrawable(
new BitmapDrawable());
popupWindow.showAsDropDown(dropView);
转载请注明原文地址: https://ju.6miu.com/read-14984.html