/**
* Created by twy on 2017/7/7.
*/
public class MyPopWindow extends PopupWindow {
public MyPopWindow(final Activity context,View view){
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
int h = context.getWindowManager().getDefaultDisplay().getHeight();
int w = context.getWindowManager().getDefaultDisplay().getWidth();
this.setContentView(view);
this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
this.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
this.setFocusable(true);
this.setOutsideTouchable(true);
this.update();
ColorDrawable dw = new ColorDrawable(-00000);
this.setBackgroundDrawable(dw);
this.setAnimationStyle(R.style.AnimationPreview);
}
@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 7.0上PopupWindow.showAsDropDown不起作用的解决方法
最新推荐文章于 2021-03-13 10:37:51 发布
本文介绍了一种自定义PopupWindow的方法,通过继承PopupWindow并覆盖其showAsDropDown方法来实现更灵活的弹窗显示效果。文章详细展示了如何根据屏幕尺寸调整PopupWindow的高度,并提供了动画效果。
2510

被折叠的 条评论
为什么被折叠?



