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

The container moves at each show #1

Closed
galex opened this issue Sep 2, 2011 · 4 comments
Closed

The container moves at each show #1

galex opened this issue Sep 2, 2011 · 4 comments

Comments

@galex
Copy link

galex commented Sep 2, 2011

Hi, awesome lib but there's an annoying major bug :

Each time the QuickAction is showed, the container (not the arrow) moves to the left for some pixels.
After few openings, the QuickAction is not even under the arrow.

I used it with a button (in an action bar) at the maximum right of the screen.

Best regards,
Alex.

Screenshot : http://hpics.li/b1da65e

@jeacott
Copy link

jeacott commented Sep 20, 2011

A related problem is that the arrow position also gets messed up if you add different sized content to an existing quickaction object or try right aligning the control on a very small button.
the reason is because of the way the arrow left margin is calculated. would be nice if it were fixed.

@TheVaan
Copy link

TheVaan commented Oct 6, 2011

Dudes, I solved your problem and I think this could be fixed in the main release too:

Replace the show function of the class QuickAction with the following:

public void show (View anchor) {
    preShow();

    int xPos, yPos, arrowPos; // int arrowPos is needed cause position of arrow has to be diffrent for buttons that are small and aligned to the right

    int[] location      = new int[2];

    anchor.getLocationOnScreen(location);

    Rect anchorRect     = new Rect(location[0], location[1], location[0] + anchor.getWidth(), location[1] 
                        + anchor.getHeight());

    //mRootView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    mRootView.measure(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    int rootHeight      = mRootView.getMeasuredHeight();
    int rootWidth       = mRootView.getMeasuredWidth();

    int screenWidth     = mWindowManager.getDefaultDisplay().getWidth();
    int screenHeight    = mWindowManager.getDefaultDisplay().getHeight();

    //automatically get X coord of popup (top left)
    if ((anchorRect.left + rootWidth) > screenWidth) {
        xPos = anchorRect.right - (rootWidth-anchor.getWidth());
        arrowPos = anchorRect.right-xPos; // normally it is anchorRect.left-xPos but then there is a gap which is getting bigger on pressing the button a few times.
    } else {
        if (anchor.getWidth() > rootWidth) {
            xPos = anchorRect.centerX() - (rootWidth/2);
        } else {
            xPos = anchorRect.left;
        }
        arrowPos = anchorRect.centerX()-xPos; // that is the developers default
    }

    int dyTop           = anchorRect.top;
    int dyBottom        = screenHeight - anchorRect.bottom;

    boolean onTop       = (dyTop > dyBottom) ? true : false;

    if (onTop) {
        if (rootHeight > dyTop) {
            yPos            = 15;
            LayoutParams l  = mScroller.getLayoutParams();
            l.height        = dyTop - anchor.getHeight();
        } else {
            yPos = anchorRect.top - rootHeight;
        }
    } else {
        yPos = anchorRect.bottom;

        if (rootHeight > dyBottom) { 
            LayoutParams l  = mScroller.getLayoutParams();
            l.height        = dyBottom;
        }
    }

    showArrow(((onTop) ? R.id.arrow_down : R.id.arrow_up), arrowPos); // replaced developers default value with the var so in special cases the popup AND the arrow are displayed constrained to the right

    setAnimationStyle(screenWidth, anchorRect.centerX(), onTop);

    mWindow.showAtLocation(anchor, Gravity.NO_GRAVITY, xPos, yPos);
}

You can see a screenshot here: http://twitpic.com/6w4lnj (sorry for motion blur but I'm not allowed to show the layout of the app currently :/)

Hope I could help you!

@lorensiuswlt
Copy link
Owner

This bug has been fixed on current update, thanx TheVaan for giving me the clue..

@jeacott
Copy link

jeacott commented Nov 29, 2011

2 things - the existing update to the main line doesnt work properly for me.

  1. on rotation it calculates the arrow location incorrectly. I did this to fix :

//automatically get X coord of popup (top left)
//if ((anchorRect.left + rootWidth) > screenWidth) {
xPos = anchorRect.left - (rootWidth-anchor.getWidth());
xPos = (xPos < 0) ? 0 : xPos;
arrowPos = anchorRect.centerX()-xPos;
/} else {
if (anchor.getWidth() > rootWidth) {
xPos = anchorRect.centerX() - (rootWidth/2);
} else {
xPos = anchorRect.left;
}
arrowPos = anchorRect.centerX()-xPos;
}
/

  1. on my devices I needed to restore the line:
    mRootView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

without it I just get exceptions.

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

4 participants