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

When the search icon is being clicked for the first time, animation effect is not visible #6

Open
yccheok opened this issue Sep 29, 2018 · 2 comments

Comments

@yccheok
Copy link

yccheok commented Sep 29, 2018

I notice that when the search icon is being clicked for the first time, animation effect is not visible. The animation effect will only be visible for 2nd time.

I look at the source code. However, I have no idea why there's such strange behavior.

Thank you

@yccheok
Copy link
Author

yccheok commented Sep 29, 2018

I think the reason is that, when first time click is being performed, searchtoolbar is not inflated yet. Hence, its dimension is not available. I would suggest using the following way to obtain width, cx and cy, which is more reliable. Especially for some menu item with ifRoom, it is difficult to pick a correct posFromRight value.

private int getActionSearchMenuLocation() {
    View menuSearch = findViewById(R.id.action_search);

    // Found it! Do what you need with the button
    int[] menuSearchLocation = new int[2];
    menuSearch.getLocationInWindow(menuSearchLocation);
    return menuSearchLocation[0] + menuSearch.getWidth() / 2;
}

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private void circleReveal(int viewID, int posFromRight, boolean containsOverflow, final boolean isShow)
{
    final View myView = findViewById(viewID);

    int width=this.toolbar.getWidth();

    int cx=getActionSearchMenuLocation();
    int cy=this.toolbar.getHeight()/2;

    Animator anim;
    if(isShow)
        anim = ViewAnimationUtils.createCircularReveal(myView, cx, cy, 0,(float)width);
    else
        anim = ViewAnimationUtils.createCircularReveal(myView, cx, cy, (float)width, 0);

    anim.setDuration((long)220);

    // make the view invisible when the animation is done
    anim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if(!isShow)
            {
                super.onAnimationEnd(animation);
                myView.setVisibility(View.INVISIBLE);
            }
        }
    });

    // make the view visible and start the animation
    if(isShow)
        myView.setVisibility(View.VISIBLE);

    // start the animation
    anim.start();


}

@Muhammadwahab
Copy link

I also face this problem after an hour of debugging and research i figure out the the issue.This happens because search toolbar initially is Gone State.Search Toolbar view did not inflate when animation start method trigger try changing View.Gone to View.Invisible in XMl layout Now it work Perfectly.In the end Kudos to developer who make this search bar tutorial for beginner (Y)

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

2 participants