All Projects → russelarms → Offsetanimator

russelarms / Offsetanimator

Licence: mit
Animations driven by finger movement

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Offsetanimator

FastBanner
🔥快速轮播图,支持自定义布局和使用自有图片显示组件
Stars: ✭ 27 (-91.48%)
Mutual labels:  viewpager
Transformerslayout
🔥 App金刚区导航菜单,类似淘宝、QQ音乐等APP导航,方格布局横向多行滑动翻页带滚动条
Stars: ✭ 258 (-18.61%)
Mutual labels:  viewpager
Flowhelper
帮助您迅速构建顶部Tab,比如今日头条效果,热搜、搜索记录、与ViewPager/ViewPager2搭配的工具类;
Stars: ✭ 295 (-6.94%)
Mutual labels:  viewpager
Reside-Menu
By applying viewpager animation you can also make AMAZING Reside Menu's
Stars: ✭ 72 (-77.29%)
Mutual labels:  viewpager
Inkeverticalviewpagerlive
仿映客viewPager上下滑动切换直播
Stars: ✭ 258 (-18.61%)
Mutual labels:  viewpager
Cmpagetitleview
✍️一分钟集成类似抖音,新浪微博,腾讯视频,网易新闻,今日头条等常见的标题栏样式,api灵活易扩展,支持Cocoapods和Masonry布局,支持ChildController的完整生命周期
Stars: ✭ 270 (-14.83%)
Mutual labels:  viewpager
emotic
PyTorch implementation of Emotic CNN methodology to recognize emotions in images using context information.
Stars: ✭ 57 (-82.02%)
Mutual labels:  scene
Cardslideview
一行代码实现ViewPager卡片效果,比ViewPager2更强大,底层同样是RecyclerView
Stars: ✭ 301 (-5.05%)
Mutual labels:  viewpager
Wowoviewpager
Combine ViewPager and Animations to provide a simple way to create applications' guide pages.
Stars: ✭ 2,749 (+767.19%)
Mutual labels:  viewpager
Eleme Master
高仿饿了么3.0版本点餐页面
Stars: ✭ 297 (-6.31%)
Mutual labels:  viewpager
tdme2
TDME2 - ThreeDeeMiniEngine2 is a lightweight, multi-platform 3D engine including tools suited for 3D game/application development using C++
Stars: ✭ 86 (-72.87%)
Mutual labels:  scene
Transitionexample
a demo of Transition Framework
Stars: ✭ 257 (-18.93%)
Mutual labels:  scene
Viewpagertransition
viewpager with parallax pages, together with vertical sliding (or click) and activity transition
Stars: ✭ 3,017 (+851.74%)
Mutual labels:  viewpager
scrollxp
Alpine.js-esque library for scrolling animations on websites
Stars: ✭ 50 (-84.23%)
Mutual labels:  scene
Arkit
ARKit Base Project. Place virtual objects based on WWDC example project
Stars: ✭ 297 (-6.31%)
Mutual labels:  scene
Antonio
Android library for the adapter view (RecyclerView, ViewPager, ViewPager2)
Stars: ✭ 89 (-71.92%)
Mutual labels:  viewpager
Scena
🎬 Scena is a component that represents the timeline of Scene.js. You can control time, properties, and items.
Stars: ✭ 259 (-18.3%)
Mutual labels:  scene
Loopingviewpager
A ViewPager and PagerAdapter combination that support auto scroll, infinite loop and page indicators.
Stars: ✭ 310 (-2.21%)
Mutual labels:  viewpager
Aframe Environment Component
🌄 Infinite background environments for A-Frame in a line of HTML.
Stars: ✭ 300 (-5.36%)
Mutual labels:  scene
Bannerview
横幅广告图片轮播控件
Stars: ✭ 290 (-8.52%)
Mutual labels:  viewpager

OffsetAnimator

OffsetAnimator lets animate objects basing on touchevents, so users can be engaged in an animation process.

Yellow submarine

Usage

Add the library to your project:

  1. Add it in your root build.gradle at the end of repositories:
allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}
  1. Add the dependency:
dependencies {
    compile 'com.github.russelarms:offsetanimator:1.0.2'
}

Requirements

Min sdk version is 11. The library doesn't have any transitive dependencies.

Tutorial

A Comprehensive tutorial.

Scene

To create viewpager-based animation you should bind a scene to position updates:

ViewPagerAnimatorAdapter animatorAdapter = new ViewPagerAnimatorAdapter(scene.getScene());
viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        super.onPageScrolled(position, positionOffset, positionOffsetPixels);
        animatorAdapter.onPageScrolled(position, positionOffset);
    }
});

Then create a scene instance and pass it a root view and an initializer function:

Scene.create(getRootView(), () -> initSteps());

Scripting

Script desired animation like this:

private void initSteps() {
    scene.page(0).step(0)
            .createAnimation(ocean.getY(), ocean.getY() - convertDIPToPixels(getContext(), 120))
            .setStartThreshold(0.5f)
            .setDuration(0.8f)
            .setInterpolator(new DecelerateInterpolator())
            .setListener(value -> ocean.setY(value));
}

A single page is taken as 1.0f. So duration 0.5f is a half of a distance.

Lazy initialization

It is not always convenient to specify exact view positions after some script done, so we can pass a lazy initializer. In this example animator will be initialized only on page 3 with corresponding coordinates:

scene.page(3).step(3)
        .createAnimation(() -> AnimatorFactory.createAnimator(fishLeftBottom.getY(), fishLeftBottom.getY() + screenDimensions.y / 2))
        .setDuration(0.5f)
        .setListener(value -> fishLeftBottom.setY(value));

Here's how to set the rotation:

scene.page(2).step(2)
        .createAnimation(0, 90)
        .setDuration(0.25f)
        .setListener(value -> submarine.setRotation(value));

Interpolators

We can specify an interpolator (from android.view.animation). The library ships its own SpringInterpolator:

scene.page(1).step(0)
        .createAnimation(1926, 1032)
        .setInterpolator(new SpringInterpolator(0.8f))
        .setListener(value -> submarine.setY(value));

Arc animations

Create arc animation:

scene.page(2).step(1)
        .createAnimation(() -> AnimatorFactory.createArcAnimator(submarine,
                Utils.centerX(submarine),
                convertDIPToPixels(getContext(), 48),
                submarine.getX() + submarine.getWidth() / 2,
                Utils.centerY(submarine),
                180f, Side.RIGHT))
        .setStartThreshold(0.5f)
        .setDuration(0.5f);

While standard OffsetAnimator requires user to set listeners and update fields by hand, arc animator doesn't need listener: it assigns value implicitly.

Inheritance

OffsetAnimator is open to be inherited:

public class AnotherOffsetAnimator extends OffsetAnimator {

    public AnotherOffsetAnimator(float x1, float x2) {
        super(x1, x2);
    }

    @Override
    public void animate(float position) {
        super.animate(position);
    }
}

and to be used with a scene:

scene.page(3).step(1)
        .createAnimation(() -> new AnotherOffsetAnimator(fishRight.getX(), fishRight.getX() + convertDIPToPixels(getContext(), 160)))
        .setDuration(0.5f)
        .setListener(value -> fishRight.setX(value));

License

OffsetAnimator is available under the MIT license. See the LICENSE file for more info. The library uses some code from https://github.com/asyl/ArcAnimator for arc animations.

The submarine and the fish images picked from freepik.com: Designed by Freepik Background vector created by Freepik

Copyright 2017 russelarms.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].