Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the effect of Water ripple in Android

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report