Android读书笔记-----View动画

来源:互联网 发布:淘宝怎么避免虚假交易 编辑:程序博客网 时间:2024/05/24 06:28

(文章内容来源于Android开发艺术探索)

View动画是通过对场景里的对象不断做图像的变换(平移,缩放,旋转,透明度)从产生的动画效果。使用view动画,首先要创建动画的xml,路径为res/anim/filename.xml.四种动画的名字TranslateAnimation,ScaleAnimation,RotateAnimation,AlphaAnimation。分别为平移动画,缩放动画,旋转动画,渐变动画。使用格式:
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"    android:interpolator="@android:anim/accelerate_interpolator"    android:shareInterpolator="true"    >   <alpha       android:fromAlpha="float"       android:toAlpha="float"       ></alpha>    <scale        android:fromXScale="float"        android:toXScale="float"        android:fromYScale="float"        android:toYScale="float"        android:pivotX="float|%"        android:pivotY="float|%"        />    <translate        android:fromXDelta="float"        android:fromYDelta="float"        android:pivotX="float|%"        android:pivotY="float|%"        ></translate>    <rotate        android:fromDegrees="float"        android:toDegrees="float"        android:pivotX="float|%"        android:pivotY="float|%"        ></rotate></set>

interpolator :插值器 表示集合中的动画是否和集合共享一个插值器影响动画的速度,有匀速和加速之分。
fromDegress:旋转开始的角度
privotX/Y 轴点的坐标
duration:持续时间
fillAfter:动画结束后View是否停留在结束位置

应用动画:

Animation animation=AnimatonUtils.loadAnimation(this,R.anim.animation_name);
mView.startAnimation(animation);

自定义View动画 通过集成Animation类 编写,大多是矩阵

帧动画:

顺序的播放一组自定义好的图片

<?xml version="1.0" encoding="utf-8"?><animation-list xmlns:android="http://schemas.android.com/apk/res/android"    android:oneshot="false"    >   <item android:drawable="@drawable/imgage1" android:duration="500"></item></animation-list>

LayoutAnimation:针对ViewGroup制定的动画效果。可以使ViewGroup的每一个子元素出场时都具有这种动画效果。

    <layoutAnimation        android:delay="float|0.5"        android:animationOrder="normal"        android:animation="@anim/abc_fade_in"        >   </layoutAnimation>

delay 延时的比例,如果总的进场时间为300,0.5代表每一个元素都要延时150m 进场
animationOrder:元素入场顺序
normal :
reverse :逆向
random :随机
animation:制定动画效果 引用写好的动画

使用LayoutAnimation:

1.控件的 android:layoutAnimaioin属性 引入控件
2.代码的方式
Animation animation=AnimationUtils.loadAnimation(this,R.anim_item);
LayoutAnimationController controller=new Layout…….(animation);
controller.set…….
viewgroup.setLayoutAnimtion(controller);

改变Activity的切换效果

overridePendingTransition(R.anim_enter_anim,R.anim.exit_anim);
进入时的动画效果和结束时的动画效果。
注意,必须写在startActiviy或者onfinish后才可以。
注:第一个是下一页要进入的动画效果
第二个是当前页消失的动画效果

属性动画

对任意对象的属性进行动画效果,对API 11以前的使用属性动画需要nineoldandroids。
常用的属性动画ValueAnimator,ObjectAniator,AnimatorSet。
使用方式
ObjectAnimator.ofFloat(view,”translationY”,y);
translation——>propertyName 对应属性名称
y——>数值
ValueAnimation colorAnim=ObjectAnimator.ofInt(this,”backgroundColor”,startColor,endColor);
colorAnim.setDuration();
colorAnim.setRepeatCount(ValueAnimator.INFINITE);
colorAnim.setRepeatMode(ValueAnimator.REVERSE);
colorAnim.start();

动画集合
AnimatorSet set=new AnimatorSet();
set.playTogether{
ObjectAnimator.ofInt(myView,”type”,000,000);
ObjectAnimator.ofInt
ObjectAnimator.ofInt
ObjectAnimator.ofInt
}
set.duration(1111);
set.start();
建议使用代码的方式设置属性动画

0 0
原创粉丝点击