在android中的recyclerView中显示弹出按钮的确切位置

编程入门 行业动态 更新时间:2024-10-27 22:30:54
本文介绍了在android中的recyclerView中显示弹出按钮的确切位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用Android中的recyclerView在gridLayout上工作.每个网格项都有一个选项,我想在其中显示另一个类的弹出活动.请看图片-

I'm working on a gridLayout with recyclerView in android.I've a an option with each grid Item where I want to show my popup activity which is another class. Please see the image -

每个项目都有一个菜单选项.而我的弹出活动Java名称是 CustomPop.Class .我使用一个recyclerView来显示gridViews,它的holder方法就像

There is a menu option with each Item. and my popup activity java name is CustomPop.Class. I use a recyclerView for showing gridViews and its holder method is like

public void onBindViewHolder(ViewHolder holder, int position) { holder.img_chatroom_menu.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(view.getContext(), ChatroomPopup.class); view.getContext().startActivity(intent); } }); }

通过这个,我可以显示弹出活动.但是问题是它出现在活动中间,但是我希望它在菜单选项旁边打开.

By this I can show the popup activity. But the problem is It's appear in the middle of the activity but I want it to open beside the menu option.

推荐答案

根据我的上述评论 ,您可以使用 弹出菜单

as per my above comment you can use Popup Menu

Android弹出菜单在锚文本下方显示菜单(如果空格可用,否则在锚文本上方).如果您在弹出菜单之外单击,它将消失.

Android Popup Menu displays the menu below the anchor text if space is available otherwise above the anchor text. It disappears if you click outside the popup menu.

尝试创建菜单文件

文件:poupup_menu.xml

file: poupup_menu.xml

<menu xmlns:androclass="schemas.android/apk/res/android" > <item android:id="@+id/one" android:title="One"/> <item android:id="@+id/two" android:title="Two"/> <item android:id="@+id/three" android:title="Three"/> </menu>

比使用像这样的创建弹出菜单

than use create popup menu like this

holder.img_chatroom_menu.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { //Creating the instance of PopupMenu PopupMenu popup = new PopupMenu(MainActivity.this, button1); //Inflating the Popup using xml file popup.getMenuInflater().inflate(R.menu.popup_menu, popup.getMenu()); //registering popup with OnMenuItemClickListener popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { Toast.makeText(MainActivity.this,"You Clicked : " + item.getTitle(),Toast.LENGTH_SHORT).show(); return true; } }); popup.show();//showing popup menu } });//closing the setOnClickListener method

这是示例演示链接 如何在android中创建弹出菜单

here is the sample demo links how to create pop-up menu in android

更多推荐

在android中的recyclerView中显示弹出按钮的确切位置

本文发布于:2023-10-08 08:46:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1472110.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:弹出   确切   按钮   位置   android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!