我正在使用,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" …Run Code Online (Sandbox Code Playgroud) 我想更改 Android 上弹出菜单中项目之间的间距
我希望有一个直接的解决方案,但据我所知android它不会那么简单
无论如何,我也想设置maxHeight我的弹出窗口...在这种情况下,弹出窗口由 TextView“选择奖品”锚定,因此它填充了其上方的空间,但并非所有项目都适合该空间,因此 android 会自动创建一个螺旋视图(垂直)
问题是,我知道 100% 的用户不会使用此卷轴,因此我的菜单中“旅行”下面的项目将永远不会被看到。
如何设置高度以便为所有项目留出足够的空间?
=============更新================
只是为了澄清,这不是一个旋转器,而是一个弹出菜单
this.popupCategories = new PopupMenu(this, this.categoryLabel);
for (Giveaway.GiveawayCategoryGroup catGroup : categoryGroups) {
SubMenu submenu = this.popupCategories.getMenu().addSubMenu(catGroup.getDescription(lang));
for (Giveaway.GiveawayCategory cat : (Collection<? extends Giveaway.GiveawayCategory>) catGroup.getCategories()) {
if (cat.isActive())
submenu.add(Menu.NONE, cat.getValue().hashCode(), (int) cat.getOrder(), cat.getDescription(lang));
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试在按下某个菜单项时创建一个弹出窗口.我想我有大部分代码,但是我不知道该怎么做showAtLocation(...)或showAsDropDown(...).
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
...
case R.id.about:
displayPopupWindow();
return true;
...
}
}
public void displayPopupWindow() {
PopupWindow popup = new PopupWindow(this);
View layout = getLayoutInflater().inflate(R.layout.popup, null);
popup.setContentView(layout);
popup.setOutsideTouchable(true);
popup.setFocusable(true);
popup.showAtLocation(??, Gravity.CENTER, 0, 0);
}
Run Code Online (Sandbox Code Playgroud)
我应该为菜单视图添加什么,还是应该以另一种方式执行此操作?我希望这是有道理的,谢谢你的帮助!
我正在创建一个,popupWindow但是Fragment调用它时却没有显示。
这是我的popupWindow代码:
LayoutInflater layoutInflater =
(LayoutInflater)getActivity()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.popup, null);
final PopupWindow popupWindow = new PopupWindow(
popupView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
Button btnDismiss = (Button)popupView.findViewById(R.id.dismiss);
btnDismiss.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
popupWindow.dismiss();
}});
popupWindow.showAsDropDown(getView());
//popupWindow.showAsDropDown(btnOpenPopup, 50, -30);
//popupWindow.showAsDropDown(getCurrentFocus());
popupView.setOnTouchListener(new OnTouchListener() {
int orgX, orgY;
int offsetX, offsetY;
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
orgX = (int) event.getX();
orgY = (int) event.getY();
break;
case MotionEvent.ACTION_MOVE:
offsetX = (int)event.getRawX() …Run Code Online (Sandbox Code Playgroud) 请先检查我到目前为止所做的尝试,然后再进行复制.
我试图在外部触摸时关闭弹出窗口.我已经尝试了所有可用的解决方案,但它不起作用.
第一次尝试:
pwindo.setBackgroundDrawable(new BitmapDrawable());
pwindo.setFocusable(true);
pwindo.setOutsideTouchable(true);
Run Code Online (Sandbox Code Playgroud)
第二次尝试:
pwindo.setBackgroundDrawable(new ColorDrawable());
pwindo.setFocusable(true);
pwindo.setOutsideTouchable(true);
Run Code Online (Sandbox Code Playgroud)
第3次尝试:
pwindo.setBackgroundDrawable(new ColorDrawable());
pwindo.setFocusable(true);
pwindo.setOutsideTouchable(false);
Run Code Online (Sandbox Code Playgroud)
第四次尝试:
pwindo.setFocusable(true);
pwindo.setOutsideTouchable(false);
Run Code Online (Sandbox Code Playgroud)
第五次尝试:
pwindo.setOutsideTouchable(true);
Run Code Online (Sandbox Code Playgroud)
第六次尝试:
pwindo.setOutsideTouchable(false);
Run Code Online (Sandbox Code Playgroud)
第7次尝试:
pwindo.setFocusable(true);
Run Code Online (Sandbox Code Playgroud)
什么都行不通.
更新:
public void addFlyout()
{
try {
LayoutInflater inflater = TabActivity.this.getLayoutInflater();
Display display = getWindowManager().getDefaultDisplay();
Method mGetRawH = Display.class.getMethod("getRawHeight");
Method mGetRawW = Display.class.getMethod("getRawWidth");
int rawHeight = (Integer) mGetRawH.invoke(display);
View view = inflater.inflate(R.layout.flyout_list_layout,
(ViewGroup) findViewById(R.id.flyoutLayoutList));
Dialog dialog = new Dialog(TabActivity.this);
pwindo = new PopupWindow(view, 340, rawHeight- actionBar.getHeight(), true);
pwindo.showAtLocation(view, Gravity.RIGHT | Gravity.TOP, 0, …Run Code Online (Sandbox Code Playgroud) 当我单击 之外的空间时PopupWindow,窗口将关闭。但是,如果我想在ListView窗口外滚动,则滚动事件首先被识别为单击事件,并被窗口拦截,因此窗口被关闭,而滚动不被执行。
如何在ListView 窗口关闭的同时滚动,这样我就不需要再次滚动它。
我有一个包含 2 个文本视图的弹出窗口。
如果用户单击一个文本视图 toast 必须出现。我为此功能编码但显示Nullpointer exception在线far.setOnClickListener(new OnClickListener() {请帮助我。
我的代码:
btn_a.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
LayoutInflater lInflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View popup_view = lInflater.inflate(R.layout.popup_a, null);
final PopupWindow popup = new PopupWindow(popup_view,200,75,true);
popup.setFocusable(true);
popup.setBackgroundDrawable(new ColorDrawable());
popup.showAsDropDown(btn_a, 0,0);
TextView far = (TextView) rootView.findViewById(R.id.fartext);
far.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getActivity(), "Clicked Far", Toast.LENGTH_SHORT).show();
}
});
}
});
Run Code Online (Sandbox Code Playgroud)