简体   繁体   English

在RecyclerView Adapter布局项目顶部显示PopupWindow

[英]display PopupWindow on top of RecyclerView Adapter layout item

I am displaying JSON data inside RecyclerView , I added long press action on RecyclerView item , which display PopupWindow . 我在RecyclerView中显示JSON数据,我对RecyclerView项目添加了长按操作,该项目显示PopupWindow I want to display that PopupWindow on Top of each Recyclerview item when i long click on it. 当我长按它时,我想在每个Recyclerview项的顶部显示该PopupWindow

but PopupWindow only display on TOP of parent screen not on top of Recyclerview item. 但是PopupWindow仅显示在父屏幕的TOP上,而不显示在Recyclerview项的顶部。

i want that PopupWindow should display at TOP of each RecyclerView item layout. 我希望PopupWindow应该显示在每个RecyclerView项目布局的顶部。

here is my code for Displaying PopupWindow 这是我的显示PopupWindow的代码

private void PopUpWindowOption(LinearLayout mainLayout)
    {

        View customView = LayoutInflater.from(context).inflate(R.layout.popup,null);

        Button closePopupBtn = (Button) customView.findViewById(R.id.closePopupBtn);

        final PopupWindow popupWindow = new PopupWindow(customView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);



        closePopupBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popupWindow.dismiss();
                Toast.makeText(context,"clicked",Toast.LENGTH_SHORT).show();
            }
        });

        popupWindow.showAtLocation(mainLayout, Gravity.TOP, 0, 0);

    }

Output 输出量

在此处输入图片说明

How can i achieve this help me. 我如何才能做到这一点对我有帮助。 Thank you 谢谢

what you are currently using is : 您当前正在使用的是:

popupWindow.showAtLocation(mainLayout, Gravity.TOP, 0, 0);

What you want to use is : 您要使用的是:

popupWindow.showAsDropDown(anchor, offsetX, offsetY, gravity);

The above code shows the popup relative to the specified anchor view. 上面的代码显示了相对于指定锚视图的弹出窗口。 you can use the view of the item at the time of OnClick or OnLongClick Event. 您可以在OnClick或OnLongClick事件时使用项目的视图。 This will show as a dropdown relative to the item. 这将显示为相对于该项目的下拉列表。 If you want to show it above the itemView, You can change it accordingly by changing the value of offsetY. 如果要将其显示在itemView上方,则可以通过更改offsetY的值进行相应的更改。 like : 喜欢 :

popupWindow.showAsDropDown(anchor, 0, -anchor.getHeight() + popupView.getHeight());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM