package net.oschina.app.util; import android.view.View; import android.view.animation.AlphaAnimation; import android.view.animation.Animation; import android.view.animation.AnimationSet; import android.view.animation.AnticipateInterpolator; import android.view.animation.OvershootInterpolator; import android.view.animation.RotateAnimation; import android.view.animation.ScaleAnimation; import android.view.animation.TranslateAnimation; import android.widget.ImageView; import android.widget.RelativeLayout; /** * 录音动画类 */ public class KJAnimations { /** * 旋转 Rotate */ public static Animation getRotateAnimation(float fromDegrees, float toDegrees, long durationMillis) { RotateAnimation rotate = new RotateAnimation(fromDegrees, toDegrees, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); rotate.setDuration(durationMillis); rotate.setFillAfter(true); return rotate; } /** * 透明度 Alpha */ public static Animation getAlphaAnimation(float fromAlpha, float toAlpha, long durationMillis) { AlphaAnimation alpha = new AlphaAnimation(fromAlpha, toAlpha); alpha.setDuration(durationMillis); alpha.setFillAfter(true); return alpha; } /** * 缩放 Scale */ public static Animation getScaleAnimation(float scaleXY, long durationMillis) { ScaleAnimation scale = new ScaleAnimation(1.0f, scaleXY, 1.0f, scaleXY, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); scale.setDuration(durationMillis); return scale; } /** * 位移 Translate */ public static Animation getTranslateAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta, long durationMillis) { TranslateAnimation translate = new TranslateAnimation(fromXDelta, toXDelta, fromYDelta, toYDelta); translate.setDuration(durationMillis); translate.setFillAfter(true); return translate; } public static Animation clickAnimation(float scaleXY, long durationMillis) { AnimationSet set = new AnimationSet(true); set.addAnimation(getScaleAnimation(scaleXY, durationMillis)); set.setDuration(durationMillis); return set; } public static Animation shakeAnimation(int X) { AnimationSet set = new AnimationSet(true); Animation anim1 = getTranslateAnimation(0, -200, 0, 0, 100); anim1.setStartOffset(100); set.addAnimation(anim1); Animation anim2 = getTranslateAnimation(-200, 400, 0, 0, 200); anim2.setStartOffset(300); set.addAnimation(anim2); Animation anim3 = getTranslateAnimation(400, -200, 0, 0, 200); anim3.setStartOffset(500); set.addAnimation(anim3); Animation anim4 = getTranslateAnimation(-200, 0, 0, 0, 100); anim4.setStartOffset(600); set.addAnimation(anim4); set.setFillAfter(true); set.setDuration(640); return set; } /** * 打开的动画 * * @param relativeLayout * 子菜单容器 * @param background * 子菜单背景 * @param menu * 菜单按钮 * @param durationMillis * 动画时间 */ public static void openAnimation(RelativeLayout relativeLayout, ImageView menu, long durationMillis) { relativeLayout.setVisibility(View.VISIBLE); for (int i = 1; i < relativeLayout.getChildCount(); i++) { ImageView imageView = null; if (relativeLayout.getChildAt(i) instanceof ImageView) { imageView = (ImageView) relativeLayout.getChildAt(i); } else { continue; } int top = imageView.getTop(); int left = imageView.getLeft(); if (top == 0) { top = (menu.getHeight() + 50) * i; } if (left == 0) { left = menu.getLeft(); } AnimationSet set = new AnimationSet(true); set.addAnimation(getRotateAnimation(-360, 0, durationMillis)); set.addAnimation(getAlphaAnimation(0.5f, 1.0f, durationMillis)); set.addAnimation(getTranslateAnimation(menu.getLeft() - left, 0, menu.getTop() - top + 30, 0, durationMillis));// 加30是由于图片上部有一些透明高度 set.setFillAfter(true); set.setDuration(durationMillis); set.setStartOffset((i * 100) / (-1 + relativeLayout.getChildCount())); set.setInterpolator(new OvershootInterpolator(1f)); imageView.startAnimation(set); } } /** * 关闭的动画 * * @param relativeLayout * 子菜单容器 * @param background * 子菜单背景 * @param menu * 菜单按钮 * @param durationMillis * 动画时间 */ public static void closeAnimation(final RelativeLayout relativeLayout, final ImageView menu, long durationMillis) { for (int i = 1; i < relativeLayout.getChildCount(); i++) { ImageView imageView = null; if (relativeLayout.getChildAt(i) instanceof ImageView) { imageView = (ImageView) relativeLayout.getChildAt(i); } else { continue; } AnimationSet set = new AnimationSet(true); set.addAnimation(getRotateAnimation(0, -360, durationMillis)); set.addAnimation(getAlphaAnimation(1.0f, 0.5f, durationMillis)); set.addAnimation(getTranslateAnimation(0, menu.getLeft() - imageView.getLeft(), 0, menu.getTop() - imageView.getTop() + 30, durationMillis));// 加30是由于图片上部有一些透明高度 set.setFillAfter(true); set.setDuration(durationMillis); set.setStartOffset(((relativeLayout.getChildCount() - i) * 100) / (-1 + relativeLayout.getChildCount())); set.setInterpolator(new AnticipateInterpolator(1f)); set.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation arg0) {} @Override public void onAnimationRepeat(Animation arg0) {} @Override public void onAnimationEnd(Animation arg0) { relativeLayout.setVisibility(View.GONE); } }); imageView.startAnimation(set); } } }
相关推荐
1. **动画(Animations)**:Flutter的核心在于其强大的动画系统,它允许开发者创建流畅、复杂的交互效果。我们可以使用`AnimationController`来控制动画的开始、停止和重置。`AnimationController`与`Tween`对象...
2. **动画(Animations)**:定义一系列关键帧,使元素在一段时间内按特定路径变化,可用来模拟录音过程中的波形动画。 3. **伪类和伪元素(Pseudo-classes and Pseudo-elements)**:如`:hover`、`:active`和`:...
“旋转出”、“棋盒棱形”、“垂直百叶窗”、“左拉”等效果,主要依赖于变换(Transforms)和动画(Animations)。通过组合不同的变换类型,如ScaleTransform、RotateTransform和TranslateTransform,以及利用...
LCVoiceHud是一款专为移动应用设计的录音动画组件,其主要功能是在用户进行录音时提供直观、动态的视觉反馈。这款组件对于提升用户体验尤其重要,因为它能够清晰地告知用户当前录音的状态,使得用户知道何时可以开始...
4. **动画(Animations)**: - `animation-duration`指定动画的总时长,控制磁带转动的速度。 - `animation-timing-function`定义了动画随时间的进度速度,可以是线性的,也可以是缓动函数,如`ease-in-out`,...
5. **动画(Animations)**:CSS3的动画允许开发者自定义一系列关键帧,并按照时间顺序播放。对于磁带转动特效,我们可以创建一个动画,设定多个关键帧来描述磁带从静止到转动的过程,以及在播放和停止之间的变化。 ...
2. **Animations(动画)**:允许我们定义更复杂的动画序列,包括多个关键帧。在波浪音阶动画中,可以利用`@keyframes`规则来定义音阶上升和下降的关键状态,并指定动画的持续时间、延迟、次数和方向。 3. **...
6. **动画(Animations)**:CSS3动画提供了更精细的控制,可以创建复杂的交互式效果,如录音条的实时记录和回放动画,或者磁带录音机的“转盘”效果。 7. **盒模型(Box Model)**:通过调整`padding`、`margin`和...
它引入了许多新的选择器和属性,如transitions(过渡)、animations(动画)和transform(变换),使得开发者可以轻松创建出复杂的动态效果。在Siri动画特效中,CSS3可能被用于实现Siri图标滑动出现、颜色渐变、圆角...
为了实现动画效果,我们可以使用CADisplayLink或者UIView的animate(withDuration:animations:)方法,定期重新绘制视图并更新曲线的位置和形状,以反映新的声音数据。 为了优化性能,我们可能需要使用Core Animation...
呈现以asciinema格式制作的asciicast格式的录音 安装 termtosvg与Linux,macOS和BSD操作系统兼容,要求Python> = 3.5,并且可以使用pip如下安装: # Create virtualenv named '.venv' python3 -m