java - 当我们单击相应的项目时,如何在 recyclerview 项目顶部显示弹出窗口
问题描述
这是所需的屏幕设计:
根据上面的截图,我需要设计布局:当我点击 recyclerview 项目行的添加按钮时,添加选项需要显示。
这是我的 XML 代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/cell"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorLightWhite">
<LinearLayout
android:id="@+id/ll_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:visibility="visible"
android:layout_marginRight="@dimen/default_margin"
android:layout_marginLeft="@dimen/default_margin"
android:layout_marginTop="@dimen/default_margin"
android:layout_marginBottom="@dimen/default_margin"
android:weightSum="100">
<EditText
android:id="@+id/et_add_member"
android:layout_width="wrap_content"
android:layout_weight="95"
android:layout_height="42dp"
android:padding="@dimen/padding_8"
android:hint="Person"
android:background="@drawable/edit_box"/>
<ImageView
android:id="@+id/iv_addMember"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_gravity="center"
android:layout_marginLeft="@dimen/default_margin"
android:layout_centerVertical="true"
android:layout_weight="5"
android:src="@drawable/add_x" />
</LinearLayout>
<LinearLayout
android:id="@+id/include_add"
android:layout_width="210dp"
android:layout_height="wrap_content"
android:layout_below="@+id/ll_main"
android:layout_alignTop="@+id/ll_main"
android:layout_marginTop="35dp"
android:layout_marginRight="@dimen/margin_10"
android:gravity="center"
android:layout_alignParentRight="true"
android:orientation="vertical"
android:visibility="gone">
<include layout="@layout/include_members" />
</LinearLayout>
</RelativeLayout>
这是显示弹出窗口的适配器代码:
holder.ivAddMember.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
holder.include_add.setVisibility(View.VISIBLE);
}
});
include_add LinearLayout 是弹出代码,但我无法使用此代码获得确切的 UI。
谁能建议我如何在相应的项目点击顶部显示弹出窗口,如何在先前点击的项目位置关闭弹出窗口和弹出窗口设计。
解决方案
您必须在 res 文件夹中的菜单下创建 xml 文件,然后执行如下所示的功能以在所需位置显示弹出窗口
public void showPopup() {
PopupMenu popup = new PopupMenu(context, <PASS ID WHERE YOU WISH TO SHOW POPUP>);
popup.getMenuInflater().inflate(R.menu.menu_option, popup.getMenu());
Object menuHelper;
Class[] argTypes;
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.member:
// call member class or function here
return true;
case R.id.guest:
// call Guest class or function here
return true;
case R.id.my_buddies:
// call My Buddies class or function here
return true;
}
return true;
}
});
popup.show();
}
希望你能理解。
推荐阅读
- javascript - 在python中创建shopify scripttag
- java - 如果没有用户登录,System.getProperty("user.name") 会打印什么
- ios - XCode12:如何在图像中设置约束以使其响应屏幕?
- amazon-web-services - 如何通过 Cognito 用户 ID 限制访问 AWS API Gateway 端点
- .htaccess - .httaccess 不会阻止 /.well-known/acme-challenge/abc
- phpstorm - PhpStorm 2020 似乎运行得很慢。我可以改进它吗?
- node.js - 发送后无法设置标头:response.redirect() NodeJS
- xml - Delphi:NetHttpClient - 如何为 XML 请求添加/编辑/删除 HEADER VALUES
- postgresql - NestJS 中的弹性搜索
- python - 在文本文件中重复提取特定字符之间的子字符串(python)