Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show as anchor from center #7

Closed
egek92 opened this issue Mar 28, 2018 · 5 comments
Closed

show as anchor from center #7

egek92 opened this issue Mar 28, 2018 · 5 comments

Comments

@egek92
Copy link

egek92 commented Mar 28, 2018

I have a view that has width of match_parent it's also my view anchor, I want toshow my pop-up from this view's center but it either show up from left or right

@skydoves
Copy link
Owner

Did you show up using below method?

.showAtCenter(View anchor);

or

.showAtCenter(View layout, 0, 0); 

@nomizodiac
Copy link

I am also getting the same issue. I have a button at center of the screen, on button click i want to show popup menu. Button is also the anchor view i want popup to appear at button/anchor's center, but popup menu always show/align at left edge of button. By using

.showAtCenter(View anchor);
or
.showAtCenter(View layout, 0, 0);

It appear at center but does not appear above the anchor view. I want it to appear above and center of the anchor view

@skydoves
Copy link
Owner

skydoves commented Mar 29, 2018

In that case, need to set xOffset and yOffset.

final Button button = findViewById(R.id.button2);
button.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        hamburgerMenu.showAsDropDown(view, view.getMeasuredWidth()/2, -view.getMeasuredHeight()/2);
      }
  });

Use the showAsDropDown view to set the position in relation to the anchor view.
Otherwise, you can use showAtLocation.
And you can manipulate positions using xOffset and yOffset.

@nomizodiac
Copy link

@skydoves this does not worked in my case

hamburgerMenu.showAsDropDown(view, view.getMeasuredWidth()/2, -view.getMeasuredHeight()/2);

But to manipulate positions using xOffset and yOffset i need popupwindow width/height but i couldn't access it using your API. So i have now setWith(popupWidth) and then calculated the position like this

int xOffset = view.getMeasuredWidth() / 2 - popupWidth / 2; powerMenu.showAsDropDown(view, xOffset, 0);

Thanks

@skydoves
Copy link
Owner

@egek92 @nomizodiac below method is added at v2.0.3

.showAsAnchorCenter(View anchor);

and it looks more nature using with

.setAnimation(MenuAnimation.SHOW_UP_CENTER)

@skydoves skydoves closed this as completed Apr 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants