ShowAtLocation方法用于将View显示在指定的位置上,具体使用方法如下:
View view = findViewById(R.id.your_view_id);
View parentView = findViewById(R.id.parent_view_id);
ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
view.setLayoutParams(layoutParams);
int x = 100; // x坐标
int y = 200; // y坐标
popupWindow.showAtLocation(parentView, Gravity.NO_GRAVITY, x, y);
通过以上步骤,就可以将指定的View显示在指定的位置上。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:在Android中,如何优化ShowAtLocation的性能