Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize the effect of Water ripple in Android

Shulou Source: shulou.com Published: 2022-06-01 16:42:15 09月30日 Update

This article mainly shows you "Android how to achieve water ripple effect", the content is easy to understand, clear, hope to help you solve doubts, the following let the editor lead you to study and learn "Android how to achieve water ripple effect" this article.

Effect picture

Attrs.xml

Custom attribute

RippleAnimationView.java

Manage water ripple attributes and animation statu

Public class RippleAnimationView extends RelativeLayout {private Paint paint; private int radius; private int strokeWidth; private int rippleColor; private AnimatorSet animatorSet; public RippleAnimationView (Context context) {this (context, null);} public RippleAnimationView (Context context, @ Nullable AttributeSet attrs) {this (context, attrs, 0);} public RippleAnimationView (Context context, @ Nullable AttributeSet attrs, int defStyleAttr) {super (context, attrs, defStyleAttr) Init (context, attrs);} private void init (Context context, AttributeSet attrs) {paint = new Paint (); paint.setAntiAlias (true); TypedArray array = context.obtainStyledAttributes (attrs, R.styleable.RippleAnimationView); / / Water ripple filling type int rippleType = array.getInt (R.styleable.RippleAnimationView_ripple_anim_type, 0); radius = array.getInteger (R.styleable.RippleAnimationView_radius, 54) StrokeWidth = array.getInteger (R.styleable.RippleAnimationView_stroeWidth, 2); rippleColor = array.getColor (R.styleable.RippleAnimationView_ripple_anim_color, ContextCompat.getColor (context, R.color.colorAccent)); array.recycle (); / / set brush lineweight paint.setStrokeWidth (UIUtils.getInstance (). GetWidth (strokeWidth)) If (rippleType = = 0) {paint.setStyle (Paint.Style.FILL);} else {paint.setStyle (Paint.Style.STROKE);} paint.setColor (rippleColor); LayoutParams params = new LayoutParams (UIUtils.getInstance (). GetWidth (radius + strokeWidth), UIUtils.getInstance (). GetWidth (radius + strokeWidth)) Params.addRule (CENTER_IN_PARENT, TRUE); / / scaling factor float maxScale = UIUtils.getInstance (). DisplayMetricsWidth / (2 * UIUtils.getInstance (). GetWidth (radius + strokeWidth)); / / delay time int rippleDuration = 3500; int singleDelay = rippleDuration / 4 / / time interval / / Animation set List animatorList = new ArrayList (); / / instantiate the water ripple view for (int I = 0bot I)

Tags: Ripples animation effects content attributes articles loops time learning help extroversion examples differences effects easy to understand more organization state brushes knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux MySQL Shulou Technology Redmi Shulou Information