Animator动画XML实现
在res下创建文件夹animator文件夹
<?xml version="1.0" encoding="utf-8"?> <objectAnimator xmlns:android="http://schemas.android.com/apk/res/android" android:propertyName="TranslationY" android:duration="2000" android:valueFrom="0.0" android:valueTo="400.0" android:interpolator="@android:anim/accelerate_interpolator" android:valueType="floatType" android:repeatCount="1" android:repeatMode="reverse" android:startOffset="2000"/>
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:ordering="together"> <objectAnimator android:propertyName="x" android:duration="500" android:valueFrom="0" android:valueTo="400" android:valueType="floatType"/> <objectAnimator android:propertyName="y" android:duration="500" android:valueFrom="0" android:valueTo="300" android:valueType="floatType"/> </set>
<?xml version="1.0" encoding="utf-8"?> <animator xmlns:android="http://schemas.android.com/apk/res/android" android:valueFrom="0" android:valueTo="300" android:duration="1000" android:valueType="intType" android:interpolator="@android:anim/bounce_interpolator"/>
mTv = (TextView)findViewById(R.id.tv); findViewById(R.id.start_anim).setOnClickListener(new View.OnClickListener() { public void onClick(View v) { ObjectAnimator animator = (ObjectAnimator) AnimatorInflater.loadAnimator(MainActivity.this, R.animator.object_animator); animator.setTarget(mTv); animator.start(); } });
mTv = (TextView)findViewById(R.id.tv); findViewById(R.id.start_anim).setOnClickListener(new View.OnClickListener() { public void onClick(View v) { AnimatorSet set = (AnimatorSet) AnimatorInflater.loadAnimator(MainActivity.this, R.animator.set_animator); set.setTarget(mTv); set.start(); } });
mTv = (TextView)findViewById(R.id.tv); findViewById(R.id.start_anim).setOnClickListener(new View.OnClickListener() { public void onClick(View v) { ValueAnimator valueAnimator = (ValueAnimator) AnimatorInflater.loadAnimator(MainActivity.this, R.animator.value_animator); valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { public void onAnimationUpdate(ValueAnimator animation) { int offset = (Integer)animation.getAnimatedValue(); mTv.layout( offset,offset,mTv.getWidth()+offset,mTv.getHeight() + offset); } }); valueAnimator.start(); } });
最后,关注【码上加油站】微信公众号后,有疑惑有问题想加油的小伙伴可以码上加入社群,让我们一起码上加油吧!!!
posted on 2018-12-29 17:17 LoaderMan 阅读(1226) 评论(0) 编辑 收藏 举报