我想在屏幕中间显示我的弹出窗口。我在 MainActivity 的 OnCreate 中调用它。我无法理解如何获得 showAtLocation 所要求的父 View :
public void showAtLocation(android.view.View父级,int重力,int x,int y)
我拥有的是:
List<Fragment> list=new ArrayList<>();
list.add(new PageFragment1());
list.add(new PageFragment2());
list.add(new PageFragment3());
LayoutInflater inflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.layout.onboarding, null);
pager=v.findViewById(R.id.pager);
pagerAdapter=new Onboard_SlidePageAdapter(getSupportFragmentManager(),1,list);
pager.setAdapter(pagerAdapter);
onboardPopupWindow = new PopupWindow(v,500, RelativeLayout.LayoutParams.WRAP_CONTENT, true);
onboardPopupWindow.setElevation(10);
onboardPopupWindow.showAtLocation(this,Gravity.CENTER,0,0);
我知道我无法传递“this”,但没有 this.getView() 或类似的
最佳答案
替换
onboardPopupWindow.showAtLocation(this,Gravity.CENTER,0,0);
与
v.post(new Runnable() {
public void run() {
onboardPopupWindow.showAtLocation(v,Gravity.CENTER, 0, 0);
}
});
关于java - OnCreate 中的 PopupWindow 和 ShowAtLocation - 如何获取父 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60414500/