Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/184.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 在屏幕最左侧显示ListPopupWindow_Android - Fatal编程技术网

Android 在屏幕最左侧显示ListPopupWindow

Android 在屏幕最左侧显示ListPopupWindow,android,Android,我可以通过以下代码在屏幕最左侧显示ListPopupWindow @Override public View onCreateActionView() { LayoutInflater layoutInflater = LayoutInflater.from(mContext); final View actionItem = layoutInflater.inflate(R.layout.list_table_view_action_provider, null);

我可以通过以下代码在屏幕最左侧显示ListPopupWindow

@Override
public View onCreateActionView() {
    LayoutInflater layoutInflater = LayoutInflater.from(mContext);

    final View actionItem = layoutInflater.inflate(R.layout.list_table_view_action_provider, null);

    final ImageButton button = (ImageButton) actionItem.findViewById(R.id.button);
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mListPopupWindow = new ListPopupWindow(mContext);
            mListPopupWindow.setAnchorView(actionItem);
            mListPopupWindow.setAdapter(mAdapter);
            mListPopupWindow.setModal(true);
            mListPopupWindow.setContentWidth(150);

            // Display mListPopupWindow on most left of the screen
            mListPopupWindow.setHorizontalOffset(-1000);


            mListPopupWindow.setOnItemClickListener(ListTableViewActionProvider.this);

            mListPopupWindow.show();
            mListPopupWindow.setOnDismissListener(ListTableViewActionProvider.this);
        }
    });

    return actionItem;
}
“mListPopupWindow.setHorizontalOffset(-1000);”太糟糕了。
是否有其他解决方案?

尝试将活动的最外层布局/视图组作为定位点,偏移量为0。或者,您也可以使用弹出窗口并将x和y设为0。您可以锚定到主图标,使用
findViewById(android.R.id.home)
获取视图。弹出窗口将不会与屏幕左边缘齐平;主页图标在左边有一些空白(为“向上”启示箭头腾出空间)。参见本文