android - 在屏幕的最左侧显示ListPopupWindow

标签 android

我可以通过下面的代码在屏幕的最左边显示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);”太糟糕。
还有别的办法吗?

最佳答案

下面是ListPopupWindow示例,

        View  menuItemView = getActivity().findViewById( R.id.menu_filter );
        ListPopupWindow popup        = new ListPopupWindow( getActivity() );

        popup.setHorizontalOffset( -200 );
        popup.setVerticalOffset( -100 );

        popup.setAnchorView( menuItemView );
        popup.setWidth( 400 );
        popup.setModal( true );
        popup.setHeight( ListPopupWindow.WRAP_CONTENT );

        ListAdapter adapter = new MyAdapter( getActivity());
        popup.setAdapter( adapter );

        popup.show();

关于android - 在屏幕的最左侧显示ListPopupWindow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9906786/

相关文章:

android - 使用 ProgressBar.setProgressDrawable 的颜色问题

java - 使用 AND/OR 运算符的 SQL WHERE 子句

android - iBeacon 后台扫描

android - 在 Android 集成测试中使用 WireMock 时出现 NoSuchMethodError

Android 幻灯片动画与弹跳

android - Applovin AdclickListener 无法在 Android 中工作

Android同心圆缩放动画

android - 从 res 从 Drawable 创建位图的有效方法(BitmapFactory 与类型转换)

android - 从 Google plus 帐户注销在 android 中不工作,显示空指针异常

android - Flutter Android SDK 版本 28 错误,但我使用的是 30