GithubHelp home page GithubHelp logo

animatorx's Introduction

AnimatorX

动画 + 协程 = Power!

准备

  1. Add jitpack to build.gradle
allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}
  1. Add dependency
dependencies {
	implementation 'com.github.ssseasonnn:AnimatorX:1.0.0'
}

使用方法

执行单个动画

  • 位移动画
launch {
    //沿着X轴正向移动300像素
    button.translationX(0f, 300f)
}

launch {
    //沿着Y轴正向移动300像素
    button.translationY(0f, 300f)
}

launch {
    //沿着Z轴正向移动300像素
    button.translationZ(0f, 300f)
}
  • 缩放动画
launch {
    //沿着X轴缩放,从原始大小放大到3倍大小
    button.scaleX(1f, 3f)
}

launch {
    //沿着Y轴缩放,从原始大小放大到3倍大小
    button.scaleY(1f, 3f)
}
  • 旋转动画
launch {
    //沿着button中心旋转180度
    button.rotation(0f, 180f)
}

launch {
    //沿着X轴旋转
    button.rotationX(0f, 180f)
}

launch {
    //沿着Y轴旋转
    button.rotationY(0f, 180f)
}
  • 渐变动画
launch {
    //渐变透明
    button.alpha(1f, 0f)
}

组合多个动画

  • 顺序执行,只需要把需要执行的动画按照从上到下的顺序排列即可
launch {
    button1.translationX(0f, 300f)
    button2.alpha(1.0f, 0.1f)
    button3.rotation(0f, 180f)
    button4.scaleX(1.0f, 3f)

    //依次执行button1的位移动画,button2的渐变动画,button3的旋转动画,button4的缩放动画
}
  • 并列执行,只需要把需要同时运行的动画放进async块中即可
launch {
    val anim1 = async { button1.translationX(0f, 300f)  }
    val anim2 = async { button2.alpha(1.0f, 0.1f) }
    val anim3 = async { button3.rotation(0f, 180f) }
    val anim4 = async { button4.scaleX(1.0f, 3f) }
    awaitAll(anim1, anim2, anim3, anim4)

    //这次四个动画将会一起执行
}

最后

除此之外,你还能享受到所有协程的其他特性,例如使用 delay() 对动画进行延时, 使用 repeat() 对动画进行重复播放等等,发挥你的想象力把!

License

Copyright 2019 Season.Zlc

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

animatorx's People

Contributors

ssseasonnn avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.