Android 常用知识点-动画

动画:

两种使用方法:一:在res下建立anim文件然后新建xml文件,二:代码中实现

补间动画:也叫(View动画),不会移动空间的实际位置

  缩放:TranslateAnimation ,   平移:ScaleAnimation,旋转:RotateAnimation,透明:AlphaAnimation


Animation属性:

xml属性 jav代码 作用
android:detachWallpaper setDetachWallpaper(boolean) 是否在壁纸上运行
android:duration setDuration(long) 动画的持续时间
android:fillAfter setFillAfter(boolean) 动画结束后是否停留在结束位置
android:fillBefore setFillBefore(boolean) 动画结束时是否还原开始位置
android:fillEnabled setFillEnabled(boolean) 同上,与fillBefore相同
android:interpolator setInterpolator(Interpolator) 设置插值器
android:repeatCount setRepeatCount(int) 重复次数
android:repeatMode setRepeatMode(int) 有两种重复类型,reverse倒序回放,restart从头播放
android:startOffset setStartOffset(long) 开启动画startAnimation(animation)之后等待执行运行动画的时间
android:zAdjustment setZAdjustment(int) 表示被设置动画的内容运行时在Z轴上的位置(top/bottom/normal),默认为normal
帧动画:

 帧动画是顺序播放一组预先定义好的图片,类似播放电影。需要用到AnimationDrawable这个类。

使用方法:在res下建立drawable文件夹建立animation-list,将图片放入文件夹内

Android 常用知识点-动画

ImageView,代码中实现Android 常用知识点-动画

属性动画:

三个常用类:ValueAnimator,ObjectAnimator,AnimatorSet


private void initView() { Button bt = (Button) findViewById(R.id.bt_object_animation_activity); ImageView iv = (ImageView) findViewById(R.id.iv_object_animation_activity); //改变背景属性 ValueAnimator colorAnim = ObjectAnimator.ofInt(iv, "backgroundColor", Color.parseColor("#FF4081"), Color.CYAN); colorAnim.setRepeatCount(2); colorAnim.setRepeatMode(ObjectAnimator.REVERSE); colorAnim.setDuration(1000); colorAnim.setEvaluator(new ArgbEvaluator());//估值器 //动画集合 AnimatorSet set = new AnimatorSet(); set.playTogether( ObjectAnimator.ofFloat(iv, "rotationX", 0, 360),//绕x轴旋转360度 ObjectAnimator.ofFloat(iv, "rotation", 0, -90),//逆时针旋转90度 ObjectAnimator.ofFloat(iv, "translationX", 0, 90),//右移 ObjectAnimator.ofFloat(iv, "scaleY", 1, 0.5f),//y轴缩放到一半 ObjectAnimator.ofFloat(iv, "alpha", 1, 0.25f, 1)//透明度变换 ); //延迟一秒开始 set.setStartDelay(1000); bt.setOnClickListener((v) -> { //改变属性 位置 向下移动iv高的二分之一 ObjectAnimator.ofFloat(iv, "translationY", iv.getHeight() / 2).start(); //背景属性改变开始 colorAnim.start(); //集合动画 set.setDuration(3000).start(); }); }
作者:英勇青铜5 链接:https://www.jianshu.com/p/6a53ce436fd9 來源:简书 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


private void initView() { Button bt = (Button) findViewById(R.id.bt_object_animation_activity); ImageView iv = (ImageView) findViewById(R.id.iv_object_animation_activity); //改变背景属性 ValueAnimator colorAnim = ObjectAnimator.ofInt(iv, "backgroundColor", Color.parseColor("#FF4081"), Color.CYAN); colorAnim.setRepeatCount(2); colorAnim.setRepeatMode(ObjectAnimator.REVERSE); colorAnim.setDuration(1000); colorAnim.setEvaluator(new ArgbEvaluator());//估值器 //动画集合 AnimatorSet set = new AnimatorSet(); set.playTogether( ObjectAnimator.ofFloat(iv, "rotationX", 0, 360),//绕x轴旋转360度 ObjectAnimator.ofFloat(iv, "rotation", 0, -90),//逆时针旋转90度 ObjectAnimator.ofFloat(iv, "translationX", 0, 90),//右移 ObjectAnimator.ofFloat(iv, "scaleY", 1, 0.5f),//y轴缩放到一半 ObjectAnimator.ofFloat(iv, "alpha", 1, 0.25f, 1)//透明度变换 ); //延迟一秒开始 set.setStartDelay(1000); bt.setOnClickListener((v) -> { //改变属性 位置 向下移动iv高的二分之一 ObjectAnimator.ofFloat(iv, "translationY", iv.getHeight() / 2).start(); //背景属性改变开始 colorAnim.start(); //集合动画 set.setDuration(3000).start(); }); }
作者:英勇青铜5 链接:https://www.jianshu.com/p/6a53ce436fd9 來源:简书 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
默认的中心是view 中心

rotationX 围绕x轴旋转,rotationY 围绕Y轴旋转,