Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android LisPopUpWindow位于视图的右侧,没有边距_Android_Android Popupwindow - Fatal编程技术网

Android LisPopUpWindow位于视图的右侧,没有边距

Android LisPopUpWindow位于视图的右侧,没有边距,android,android-popupwindow,Android,Android Popupwindow,我正在尝试实现一个ListPopUpWindow类似于twitter的菜单Popup。但它会粘在屏幕的右侧。任何帮助都将不胜感激。我的密码在下面 弹出窗口方法 private void onListPopUp(View anchor) { ArrayList<Person> persoonItem = new ArrayList<>(); persoonItem.add(new Person(R.drawable.ic_profile_logo, "O

我正在尝试实现一个
ListPopUpWindow
类似于
twitter
的菜单
Popup
。但它会粘在屏幕的右侧。任何帮助都将不胜感激。我的密码在下面

弹出窗口方法

 private void onListPopUp(View anchor) {

    ArrayList<Person> persoonItem = new ArrayList<>();
    persoonItem.add(new Person(R.drawable.ic_profile_logo, "Oladeji Abubakar", "abubakar.oladeji@deliveryscience.co", ""));
    persoonItem.add(new Person(0, "", "", "Update Phone"));
    persoonItem.add(new Person(0, "", "", "Your Cards"));
    persoonItem.add(new Person(0, "", "", "Invite Friends"));
    persoonItem.add(new Person(0, "", "", "Logout"));

    ListPopupWindowAdapter mListPopUpWindowAdapter = new ListPopupWindowAdapter(getApplicationContext(), persoonItem);

    final ListPopupWindow pop = new ListPopupWindow(this);
    pop.setAdapter(mListPopUpWindowAdapter);
    pop.setAnchorView(anchor);
    pop.setModal(true);
    pop.setContentWidth(toolbar.getWidth() / 2);
    pop.setHeight(ListPopupWindow.WRAP_CONTENT);
    pop.setVerticalOffset(-105);
    //pop.setHorizontalOffset(100);
    //pop.setPromptPosition(20);
    //pop.setHorizontalOffset();
    pop.setPromptPosition(0);
    pop.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            pop.dismiss();
            Toast.makeText(TestActivity.this, "Clicked" + ((Person) parent.getItemAtPosition(position)).getOthers(), Toast.LENGTH_LONG).show();
        }
    });
    pop.show();
    WindowManager.LayoutParams wlp = new WindowManager.LayoutParams(toolbar.getWidth()/2, LinearLayout.LayoutParams.WRAP_CONTENT);
    wlp.gravity = Gravity.TOP | Gravity.END;
    wlp.horizontalMargin = -20;
    wlp.x = -20;
    View parentView = (View) pop.getListView().getParent();
    parentView.setLayoutParams(wlp);
}
private void onListPopUp(查看锚定){
ArrayList persoonItem=新的ArrayList();
个人物品。添加(新人物(R.drawable.ic_profile_徽标,“Oladeji Abubakar”,“Abubakar。oladeji@deliveryscience.co", ""));
添加(新人员(0、、、、“更新电话”);
添加(新的人(0、、、、“您的卡”);
添加(新人物(0、、、、“邀请朋友”);
添加(新的人(0,,,,,,,“注销”);
ListPopupWindowAdapter mListPopUpWindowAdapter=新建ListPopupWindowAdapter(getApplicationContext(),persoonItem);
最终ListPopupWindow-pop=新ListPopupWindow(此);
pop.setAdapter(MLISTPOPUPINDOWADApter);
pop.setAnchorView(锚定);
pop.setModal(true);
pop.setContentWidth(toolbar.getWidth()/2);
pop.setHeight(ListPopupWindow.WRAP_内容);
弹出设置垂直偏移(-105);
//pop.setHorizontalOffset(100);
//弹出设置提示位置(20);
//pop.setHorizontalOffset();
弹出设置提示位置(0);
pop.setOnItemClickListener(新的AdapterView.OnItemClickListener(){
@凌驾
public void onItemClick(AdapterView父对象、视图、整型位置、长id){
pop.discouse();
Toast.makeText(TestActivity.this,“单击”+((Person)parent.getItemAtPosition(position)).getOthers(),Toast.LENGTH_LONG.show();
}
});
pop.show();
WindowManager.LayoutParams wlp=新建WindowManager.LayoutParams(toolbar.getWidth()/2,LinearLayout.LayoutParams.WRAP_内容);
wlp.gravity=gravity.TOP | gravity.END;
wlp.水平边缘=-20;
wlp.x=-20;
视图父视图=(视图)pop.getListView().getParent();
parentView.setLayoutParams(wlp);
}
形象呢

这就是我想要达到的目标


您可以使用和偏移ListPopupWindow

令人困惑的是,如果定位点位于屏幕右侧,则需要将ListPopupWindow的宽度值添加到水平偏移,而垂直偏移始终基于0。当ListPopupWindow定位到右侧时,使用水平偏移宽度以下的值似乎没有任何效果。水平轴上的正值也指向右侧,因此我们反转水平值

以下代码将ListPopupUpWindow 5dp向下定位,并将ListPopupUpWindow 5dp从位于右上角的锚定位到左侧:

  final ListPopupWindow popupWindow = new ListPopupWindow(context);

  int widthPixels = convertDpToPixels(200, context);
  int horizontalOffset = -(widthPixels + convertDpToPixels(5, context));
  int verticaloffset = convertDpToPixels(5, context);

  popupWindow.setAnchorView(anchor);
  popupWindow.setWidth(widthPixels);
  popupWindow.setHorizontalOffset(horizontalOffset);
  popupWindow.setVerticalOffset(verticaloffset);

此弹出窗口是否有xml文件??请同时显示您的布局。只有ListItems有两个XML。第一个行,第二个为RoSok的剩余部分,你想从你的弹出窗口显示在中间?就让我们说右边前10-20页边距。我已经编辑了我的问题,我认为最好的解决方案是制作自己的弹出窗口,这样你就可以尽可能地管理它。你可以找到很多关于这方面的教程;)