zoukankan      html  css  js  c++  java
  • android属性动画

    动画-属性动画
    动画组合(依次展示动画)


    Drawable Animation 逐帧动画
    <animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot="true"> //true动画只播放一次,等于false时则循环播放
    <item android:drawable="@drawable/frame_1" android:duration="200" />
    <item android:drawable="@drawable/frame_2" android:duration="200" />
    <item android:drawable="@drawable/frame_3" android:duration="200" />
    <item android:drawable="@drawable/frame_4" android:duration="200" />
    </animation-list>
    不能在onCreate()方法中调用AnimationDrawable的start()方法,因为此时AnimationDrawable还未真正加载到界面中。所以,如果想启动界面就自动运行动画,可以在OnWindowFocusChanged(boolean hasFocus)中启动动画。

    属性动画 ValueAnimator核心类
    ValueAnimator anim = ValueAnimator.ofFloat(0f, 5f, 3f, 10f); //将一个值在5秒内从0过渡到5,再过渡到3,再过渡到10
    anim.setDuration(5000);
    anim.start();

    ObjectAnimator 可以直接对任意对象的任意属性进行动画操作,比如说View的alpha属性。
    ofFloat()方法的第二个参数可为任意对象
    ObjectAnimator animator = ObjectAnimator.ofFloat(textview, "alpha", 1f, 0f, 1f); //透明度
    animator.setDuration(5000);
    animator.start();
    ObjectAnimator animator = ObjectAnimator.ofFloat(textview, "rotation", 0f, 360f); //旋转
    anim.setInterpolator(new AccelerateInterpolator(2f)); //控制动画的变化速率
    animator.setDuration(5000);
    animator.start();

    组合动画-->主要AnimatorSet类
    这个类提供了一个play()方法,如果我们向这个方法中传入一个Animator对象(ValueAnimator或ObjectAnimator)将会返回一个AnimatorSet.Builder的实例,AnimatorSet.Builder中包括以下四个方法:
    after(Animator anim) 将现有动画插入到传入的动画之后执行
    after(long delay) 将现有动画延迟指定毫秒后执行
    before(Animator anim) 将现有动画插入到传入的动画之前执行
    with(Animator anim) 将现有动画和传入的动画同时执行

    ObjectAnimator moveIn = ObjectAnimator.ofFloat(textview, "translationX", -500f, 0f);
    ObjectAnimator rotate = ObjectAnimator.ofFloat(textview, "rotation", 0f, 360f);
    ObjectAnimator fadeInOut = ObjectAnimator.ofFloat(textview, "alpha", 1f, 0f, 1f);
    AnimatorSet animSet = new AnimatorSet();
    animSet.play(rotate).with(fadeInOut).after(moveIn);
    animSet.setDuration(5000);
    animSet.start();

    Animator监听器 anim.addListener(new AnimatorListener(){ }
    适配器
    anim.addListener(new AnimatorListenerAdapter() { });

    animator文件夹:
    <animator> 对应代码中的ValueAnimator
    <objectAnimator> 对应代码中的ObjectAnimator
    <set> 对应代码中的AnimatorSet

    在代码中把xml文件加载进来并将动画启动:
    Animator animator = AnimatorInflater.loadAnimator(context, R.animator.anim_file);
    animator.setTarget(view);
    animator.start();

  • 相关阅读:
    2、Windows 系统下安装 IntelliJ IDEA
    1、IntelliJ IDEA 使用说明
    C# static的用法详解
    wpf 加载窗体界面时出现异常System.IO.FileNotFoundException
    ObservableCollection绑定到TextBox
    Lambda表达式(转载)
    C#中out和ref之间的区别 转载
    WPF序列化与反序列化
    软件版本号规范与命名原则 转载
    WPF DataGrid滚动条滑动的时候背景色错乱或显示不全
  • 原文地址:https://www.cnblogs.com/tozhjj/p/7132569.html
Copyright © 2011-2022 走看看