标签:repeat UI 之间 android动画 注意 1.2 .com har 开发
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@[package:]anim/interpolator_resource" android:shareInterpolator=["true" | "false"] > <alpha android:fromAlpha="float" android:toAlpha="float" /> <scale android:fromXScale="float" android:toXScale="float" android:fromYScale="float" android:toYScale="float" android:pivotX="float" android:pivotY="float" /> <translate android:fromXDelta="float" android:toXDelta="float" android:fromYDelta="float" android:toYDelta="float" /> <rotate android:fromDegrees="float" android:toDegrees="float" android:pivotX="float" android:pivotY="float" /> <set> ... </set> </set>
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:fillAfter="false" > <translate android:duration="100" android:fromXDelta="0" android:toXDelta="100" android:fromYDelta="0" android:toYDelta="100" android:interpolator="@android:anim/linear_interpolator"/> <rotate android:duration="400" android:fromDegrees="0" android:toDegrees="90" /> </set>
Animation animation = AnimationUtils.loadAnimation(AnimationActivity.this, R.anim.filename); mButton.startAnimation(animation);
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:duration="300" android:interpolator="@android:anim/accelerate_interpolator" android:shareInterpolator="true"> <alpha android:fromAlpha="0.0" android:toAlpha="1.0"></alpha> <translate android:fromYDelta="500" android:toYDelta="0"></translate> </set> <?xml version="1.0" encoding="utf-8"?> <layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android" android:delay="0.5" android:animationOrder="normal" android:animation="@anim/anim_item"> </layoutAnimation> Animation animation = AnimationUtils.loadAnimation(this, R.anim.anim_item); LayoutAnimationController controller = new LayoutAnimationController(animation); controller.setDelay(0.5f); controller.setOrder(LayoutAnimationController.ORDER_NORMAL); v.setLayoutAnimation(controller); //或者直接在XMl中使用 <ListView android:id="@+id/list" android:cacheColorHint="#00000000" android:divider="#dddbdb" android:dividerHeight="1.0px" android:background="#fff4f7f9" android:layoutAnimation="@anim/anim_layout" android:listSelector="@android:color/transparent" android:layout_width="match_parent" android:layout_height="wrap_content"></ListView>
属性动画可以对任意对象的属性进行动画而不仅仅是View,在一定的时间间隔内完对象从一个属性值到另一个属性值得改变,但是属性动画是从Api11才开始有的.
private void startObjectAnimator(View object) { ObjectAnimator.ofFloat(object, "translationY", -object.getHeight()).start(); } private void startColorProperty(View view) { ValueAnimator colorAnim = ObjectAnimator.ofInt(view, "backgroundColor", 0xFFFF8080, 0xFF8080FF); colorAnim.setDuration(3000); colorAnim.setEvaluator(new ArgbEvaluator()); colorAnim.setRepeatCount(ValueAnimator.INFINITE); colorAnim.setRepeatMode(ValueAnimator.REVERSE); colorAnim.start(); } private void startSetProperty(View view) { AnimatorSet set = new AnimatorSet(); set.playTogether( ObjectAnimator.ofFloat(view, "rotationX", 0, 360), ObjectAnimator.ofFloat(view, "rotationY", 0, 360), ObjectAnimator.ofFloat(view, "rotation", 0, -90), ObjectAnimator.ofFloat(view, "translationX", 0, 90), ObjectAnimator.ofFloat(view, "translationY", 0, 90), ObjectAnimator.ofFloat(view, "scaleX", 1, 1.5f), ObjectAnimator.ofFloat(view, "scaleY", 0, 0.5f), ObjectAnimator.ofFloat(view, "alpha", 0, 0.25f, 1) ); set.setDuration(5 * 1000).start(); }
<?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="300" android:valueTo="200" android:valueType="intType"></objectAnimator> <objectAnimator android:propertyName="y" android:duration="300" android:valueTo="300" android:valueType="intType"></objectAnimator> </set>
AnimatorSet animatorSet = (AnimatorSet) AnimatorInflater.loadAnimator(this, R.animator.property_animator); animatorSet.setTarget(view); animatorSet.start();
public static interface AnimatorListener { default void onAnimationStart(Animator animation, boolean isReverse) { onAnimationStart(animation); } default void onAnimationEnd(Animator animation, boolean isReverse) { onAnimationEnd(animation); } void onAnimationStart(Animator animation); void onAnimationEnd(Animator animation); void onAnimationCancel(Animator animation); void onAnimationRepeat(Animator animation); }
public static interface AnimatorUpdateListener { void onAnimationUpdate(ValueAnimator animation); }
private static class ViewWrapper { private View mTarget; public ViewWrapper(View target) { this.mTarget = target; } public void setWidth(int width) { mTarget.getLayoutParams().width = width; mTarget.requestLayout(); } public int getWidth() { return mTarget.getLayoutParams().width; } } //使用上面的包装类 ViewWrapper wrapper = new ViewWrapper(view); ObjectAnimator.ofInt(wrapper, "width", 500).setDuration(5000).start();
private void performAnimator(final View target, final int start, final int end) { ValueAnimator valueAnimator = ValueAnimator.ofInt(1, 100); valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { //估值对象,方便估值的时候使用 private IntEvaluator mEvaluator = new IntEvaluator(); @Override public void onAnimationUpdate(ValueAnimator animation) { //获取当前的进度 int currentValue = (int) animation.getAnimatedValue(); float fraction = animation.getAnimatedFraction(); //重新计算width,然后设置给LayoutParams最后重新绘制 target.getLayoutParams().width = mEvaluator.evaluate(fraction, start, end); target.requestLayout(); } }); valueAnimator.setDuration(5000).start(); }
标签:repeat UI 之间 android动画 注意 1.2 .com har 开发
原文地址:https://www.cnblogs.com/coconna/p/9003080.html