gpt4 book ai didi

java - OnCreate 中的 PopupWindow 和 ShowAtLocation - 如何获取父 View ?

转载 作者:行者123 更新时间:2023-12-01 18:13:45 24 4
gpt4 key购买 nike

我想在屏幕中间显示我的弹出窗口。我在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com