这是所需的屏幕设计:
根据上面的屏幕截图,我需要设计布局:当我单击 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();
}
希望您能理解。
关于java - 当我们单击相应项目时,如何在 recyclerview 项目顶部显示弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54918872/