简体   繁体   English

如何在Android编程中将所有设备的径向菜单中心放置

[英]how to place the radial menu center of all devices in android programing

I have a radial menu. 我有一个径向菜单。 I want to align it center off all screens horizontally and vertically. 我想将其在所有屏幕的水平和垂直方向上居中对齐。 The code used to place the radial menu is: 用于放置径向菜单的代码是:

pieMenu.setCenterLocation(500,500)

but it places the menu using pixel units I think. 但它使用我认为的像素单位放置菜单。

menuExpandItem  = new RadialMenuItem(getString(R.string.about),
            getString(R.string.about));
    menuExpandItem .setDisplayIcon(R.drawable.ic_launcher);
    menuExpandItem 
            .setOnMenuItemPressed(new RadialMenuItem.RadialMenuItemClickListener() {
                @Override
                public void execute() {
                    // Can edit based on preference. Also can add animations
                    // here.
                    getSupportFragmentManager().popBackStack(null,
                            FragmentManager.POP_BACK_STACK_INCLUSIVE);
                    getSupportFragmentManager()
                            .beginTransaction()
                            .replace(mFragmentContainer.getId(),
                                    new RadialMenuAboutFragment()).commit();

                }
            });

  //  pieMenu.setDismissOnOutsideClick(true, menuLayout);
    pieMenu.setAnimationSpeed(0L);
    pieMenu.setSourceLocation(3,200);
    pieMenu.setIconSize(15, 30);
    pieMenu.setTextSize(13);
    pieMenu.setInnerRingRadius(45,90);
    pieMenu.setCenterLocation(550,1500);
    pieMenu.setOutlineColor(Color.BLACK, 225);
    pieMenu.setInnerRingColor(0xfbce25, 180);
    pieMenu.setOuterRingColor(0x0099CC, 180);
    //pieMenu.setHeader("Test Menu", 20);
    pieMenu.setCenterCircle(menuCloseItem);

    pieMenu.addMenuEntry(new ArrayList<RadialMenuItem>() {
        {
            add(menuItem);
            add(menuExpandItem);
            add(menuHome);
        }
    });

You can get the screen display dimensions in pixel grammatically using getSize as follows 您可以使用getSize以语法方式获得屏幕显示尺寸(以像素为单位),如下所示

Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;

If you're not in an Activity you can get the default Display via WINDOW_SERVICE: 如果您不在活动中,则可以通过WINDOW_SERVICE获取默认的显示:

WindowManager wm = (WindowManager)    context.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();

Now you can calculate the center and use it in your code. 现在,您可以计算中心并在代码中使用它。

pieMenu.setCenterLocation(width/2,height/2);

without seeing more code, i would do a : 没有看到更多的代码,我会做:

DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int height = displaymetrics.heightPixels;
int width = displaymetrics.widthPixels;
pieMenu.setCenterLocation(width/2,height/2);

But it would be really useful if you could provide us with more information on what, and from where, you are building it (fragment? dialog? activity? view?). 但是,如果您可以向我们提供有关构建内容的信息,以及从何处进行构建(片段,对话框,活动或视图),这将非常有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM