Skip to content

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

Open

Description

@yccheok

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

Activity

  1. yccheok commented on Sep 29, 2018

    @yccheok
    Author

    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();
    
    
    }
    
  2. Muhammadwahab commented on Oct 18, 2018

    @Muhammadwahab

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions