Coder Social home page Coder Social logo

onexuan / androidautoswitcher Goto Github PK

View Code? Open in Web Editor NEW

This project forked from marksss/androidautoswitcher

0.0 2.0 0.0 1.25 MB

AutoSwitchView, a view animating between two items for Android, supports multiple switching animations or you can customize your own strategy of animations. And its child view can be reused.

License: Apache License 2.0

Java 100.00%

androidautoswitcher's Introduction

English | 中文文档

AndroidAutoSwitcher

License Platform API Download

AutoSwitchView is a view that can automatically switch between two children (items). Compared to ViewFlipper, it has better stability for reusing its children when working on large data sets. Compared to AdapterViewFlipper, its expansibility is more excellent.

demo-gif

Usage

Add the dependency to your project build.gradle file

compile 'com.github.markshawn:auto-switcher:1.0.1'

Code in XML

    <com.switcher.AutoSwitchView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:switcher_repeatCount="1"
        app:switcher_autoStart="true"/>

If you want the switching animation to be infinite, you just need to set switcher_repeatCount -1.

Code in Activity

AutoSwitchView as = (AutoSwitchView) findViewById(R.id.yourid);
as.setAdapter(new YourAdapter());
as.setSwitchStrategy(new YourStrategy()); // See Switching Strategy
as.startSwitcher(); // If you have set autoStart true, this is not needed.

Switching Strategy

You can easily customize swtiching animations you like with SwitchStrategy. It supports both Animation and ObjectAnimator. Here are some builders of SwitchStrategy I have offered as follows.

  • AnimationStrategyBuilde: customize your own animation with Animation;
  • AnimatorStrategyBuilder: customize your own animation with ObjectAnimator;
  • CarouselStrategyBuilder: seamlessly switch between two items in different directions;
  • ContinuousStrategyBuilder: switch between items smoothly without any pauses;

An example:

as.setSwitchStrategy(
     new AnimationStrategyBuilder(this, R.anim.anim_in, R.anim.anim_out).
         build()
);

Another example:

as.setSwitchStrategy(
     new CarouselStrategyBuilder().
         setAnimDuration(900).
         setInterpolator(new AccelerateDecelerateInterpolator()).
         setMode(DirectionMode.right2Left).
         build()
);

In most cases, strategies above are enough. If you want to customize animation that is not so complicated, you can use AnimationStrategyBuilde or AnimatorStrategyBuilder with your own Animation or ObjectAnimator.

Additional

It usually is unnecessary. But if you want to customize more complicated animations, then you neeed to create your own SwitchStrategy through adding SingleOperator into BaseBuilder (init->next->withEnd) in turn to control all movements of the switcher.

new SwitchStrategy.BaseBuilder().
    init(new SingleOperator() {
        @Override
        public void operate(AutoSwitchView switcher, ChainOperator operator) {
            ...//init your animation
        }
    }).next(new SingleOperator() {
        @Override
        public void operate(AutoSwitchView switcher, ChainOperator operator) {
            ...//run your own animation
        }
    }).withEnd(new SingleOperator() {
        @Override
        public void operate(AutoSwitchView switcher, ChainOperator operator) {
            ...//cancle or end your animation
        }
    }).build();

License

AutoSwitchView is released under the Apache License Version 2.0.

androidautoswitcher's People

Contributors

marksss avatar

Watchers

 avatar  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.