我正在使用一个带有每个项目菜单的
recyclerview
。我使用弹出窗口来实现相同的效果,而不是使用弹出式menu
,因为我有一个定制的布局。我面临的问题是,当我从屏幕底部的项目中打开菜单时,我的菜单没有完全显示,并被切割了。有没有解决方法?
这是我的菜单(有4个选项)。<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/menuItemLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/shadow_menu"
android:gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="vertical">
<LinearLayout
android:id="@+id/menuAttendeeMeet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:gravity="center_vertical"
android:orientation="horizontal"
android:layout_marginTop="9dp"
android:paddingBottom="12dp"
android:paddingTop="12dp">
<ImageView
android:id="@+id/ivattendee_meet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:src="@drawable/meet_icon" />
<TextView
android:id="@+id/tvattendee_meet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Meet"
android:layout_marginRight="16dp"
android:textColor="@color/textPrimary"
android:textSize="16dp" />
</LinearLayout>
<LinearLayout
android:id="@+id/menuAttendeeChat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingBottom="12dp"
android:paddingTop="12dp">
<ImageView
android:id="@+id/ivattendee_chat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:src="@drawable/chat_icon" />
<TextView
android:id="@+id/tvattendee_chat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Chat"
android:layout_marginRight="16dp"
android:textColor="@color/textPrimary"
android:textSize="16dp" />
</LinearLayout>
<LinearLayout
android:id="@+id/menuAttendeeTakeANote"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingBottom="12dp"
android:paddingTop="12dp">
<ImageView
android:id="@+id/ivattendee_note"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:src="@drawable/take_a_note_icon" />
<TextView
android:id="@+id/tvattendee_note"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Take a note"
android:layout_marginRight="16dp"
android:textColor="@color/textPrimary"
android:textSize="16dp" />
</LinearLayout>
<LinearLayout
android:id="@+id/menuAttendeeBusinessCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:gravity="center_vertical"
android:layout_marginBottom="9dp"
android:orientation="horizontal"
android:paddingBottom="12dp"
android:paddingTop="12dp">
<ImageView
android:id="@+id/ivattendee_business_card"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:src="@drawable/business_card_icon" />
<TextView
android:id="@+id/tvattendee_business_card"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Business Card"
android:layout_marginRight="16dp"
android:textColor="@color/textPrimary"
android:textSize="16dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
这是我的适配器内弹出窗口:
final PopupWindow popupWindow = new PopupWindow(v.getContext());
LayoutInflater inflater = (LayoutInflater) v.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.layout_pop_up_menu_attendee, null);
popupWindow.setFocusable(true);
popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
popupWindow.setOutsideTouchable(true);
popupWindow.setWidth(WindowManager.LayoutParams.WRAP_CONTENT);
popupWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
popupWindow.setContentView(view);
int ivHeight = holder.ivAttendeeMenu.getHeight() - 20;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
popupWindow.showAsDropDown(holder.ivAttendeeMenu, 0, -ivHeight, Gravity.END);
}
View container;
if (android.os.Build.VERSION.SDK_INT > 22) {
container = (View) popupWindow.getContentView().getParent().getParent();
} else {
container = (View) popupWindow.getContentView().getParent();
}
WindowManager wm = (WindowManager) v.getContext().getSystemService(Context.WINDOW_SERVICE);
WindowManager.LayoutParams p = (WindowManager.LayoutParams) container.getLayoutParams();
p.flags |= WindowManager.LayoutParams.FLAG_DIM_BEHIND;
p.dimAmount = 0.3f;
wm.updateViewLayout(container, p);