Android: Ripple Background Programmatically

后端 未结 3 1940
忘掉有多难
忘掉有多难 2020-12-14 10:37

I am currently creating an Android app where someone can input their name, press a button, and then it just outputs their name back to them.

One effect that I would

3条回答
  •  孤城傲影
    2020-12-14 10:59

    EDIT:

    I tested this by making a small app

    First of all hide the view you want to reveal in this animation.

    The view can be from the same layout and in xml its visibility should be invisible so that the animation will reveal it.

    You can set the view height and width to match parent if you want to create a full screen animation...

    Take your original and reveal view both in frame layout

    In my case,I have used this:

     
    
                
                
    
    

    then in your activity on button click or some event do this:

        fab.setOnClickListener(new View.OnClickListener() {
                @TargetApi(Build.VERSION_CODES.LOLLIPOP)
                @Override
                public void onClick(View view) {
                    // previously invisible view
                    View myView = findViewById(R.id.revealview);
    
    // get the center for the clipping circle
                    int cx = myView.getWidth() / 2;
                    int cy = myView.getHeight() / 2;
    
    // get the final radius for the clipping circle
                    int finalRadius = Math.max(myView.getWidth(), myView.getHeight());
    
    // create the animator for this view (the start radius is zero)
                    Animator anim =
                            ViewAnimationUtils.createCircularReveal(myView, cx, cy, 0, finalRadius);
    
                    //Interpolator for giving effect to animation
                    anim.setInterpolator(new AccelerateDecelerateInterpolator());
                    // Duration of the animation
                    anim.setDuration(1000);
    
    // make the view visible and start the animation
                    myView.setVisibility(View.VISIBLE);
                    anim.start();
                }
            });
        }
    

    You can take detailed look at official documentation here: http://developer.android.com/training/material/animations.html

提交回复
热议问题