ViewAnimator


Source link: https://github.com/florent37/ViewAnimator

ViewAnimator

A fluent Android animation library !

Usage

Animate multiple view from one method

ViewAnimator

  .animate(image)

 .translationY(-1000, 0)

 .alpha(0,1)

  .andAnimate(text)

 .dp().translationX(-20, 0)

 .decelerate()

 .duration(2000)

  .thenAnimate(image)

 .scale(1f, 0.5f, 1f)

 .accelerate()

 .duration(1000)

  .start();

  

Without ViewAnimator

AnimatorSet animatorSet = new AnimatorSet();
 animatorSet.playTogether(
ObjectAnimator.ofFloat(image,"translationY",-1000,0),
ObjectAnimator.ofFloat(image,"alpha",0,1),
ObjectAnimator.ofFloat(text,"translationX",-200,0) );
 animatorSet.setInterpolator(new DescelerateInterpolator());
 animatorSet.setDuration(2000);
 animatorSet.addListener(new AnimatorListenerAdapter(){

  @Override public void onAnimationEnd(Animator animation) {

  AnimatorSet animatorSet2 = new AnimatorSet();

 animatorSet2.playTogether(

  ObjectAnimator.ofFloat(image,"scaleX", 1f, 0.5f, 1f),

  ObjectAnimator.ofFloat(image,"scaleY", 1f, 0.5f, 1f)

 );

 animatorSet2.setInterpolator(new AccelerateInterpolator());

 animatorSet2.setDuration(1000);

 animatorSet2.start();

}
 
}
);
 animatorSet.start();

More

Add same animation on multiples view

ViewAnimator

  .animate(image,text)

  .scale(0,1)

  .start();

Add listeners

ViewAnimator

  .animate(image)

  .scale(0,1)

  .onStart(() -> {

}
)

  .onStop(() -> {

}
)

  .start();
 

Use DP values

ViewAnimator

  .animate(image)

  .dp().translationY(-200, 0)

  .start();

Animate Height / Width

ViewAnimator

  .animate(view)

  .waitForHeight() //wait until a ViewTreeObserver notification

  .dp().width(100,200)

  .dp().height(50,100)

  .start();

Color animations

ViewAnimator

  .animate(view)

  .textColor(Color.BLACK,Color.GREEN)

  .backgroundColor(Color.WHITE,Color.BLACK)

  .start();

Rotation animations

ViewAnimator

  .animate(view)

  .rotation(360)

  .start();

Custom animations

ViewAnimator

  .animate(text)

  .custom(new AnimationListener.Update<TextView>() {

 @Override public void update(TextView view, float value) {

 view.setText(String.format("%.02f",value));

 
}

}
, 0, 1)

  .start();

Cancel animations

ViewAnimator viewAnimator = ViewAnimator

  .animate(view)

  .rotation(360)

  .start();
  viewAnimator.cancel();

Enhanced animations ( Thanks AndroidViewAnimators, NiftyDialogEffects )

.shake().interpolator(new LinearInterpolator());
 .bounceIn().interpolator(new BounceInterpolator());
 .flash().repeatCount(4);
 .flipHorizontal();
 .wave().duration(5000);
 .tada();
 .pulse();
 .standUp();
 .swing();
 .wobble();

...

Path animations ( Read http://blog.csdn.net/tianjian4592/article/details/47067161 )

 final int[] START_POINT = new int[]{
 300, 270 
}
;
  final int[] BOTTOM_POINT = new int[]{
 300, 400 
}
;
  final int[] LEFT_CONTROL_POINT = new int[]{
 450, 200 
}
;
  final int[] RIGHT_CONTROL_POINT = new int[]{
 150, 200 
}
;
  Path path = new Path();

  path.moveTo(START_POINT[0], START_POINT[1]);

  path.quadTo(RIGHT_CONTROL_POINT[0], RIGHT_CONTROL_POINT[1], BOTTOM_POINT[0], BOTTOM_POINT[1]);

  path.quadTo(LEFT_CONTROL_POINT[0], LEFT_CONTROL_POINT[1], START_POINT[0], START_POINT[1]);

  path.close();

  ViewAnimator.animate(view).path(path).repeatCount(2).start();

SVG path animations (Read http://www.w3school.com.cn/svg/svg_path.asp)

<svg width="100%" height="100%">
  <path

d="M 42.266949,70.444915 C 87.351695,30.995763 104.25847,28.177966 104.25847,28.177966 l 87.3517,36.631356 8.45339,14.088983 L 166.25,104.25847 50.720339,140.88983 c 0,0 -45.0847458,180.33898 -39.449153,194.42797 5.635594,14.08898 67.627119,183.15678 67.627119,183.15678 l 16.90678,81.7161 c 0,0 98.622885,19.72457 115.529665,22.54237 16.90678,2.8178 70.44491,-22.54237 78.8983,-33.81356 8.45339,-11.27118 76.08051,-107.07627 33.81356,-126.80085 -42.26695,-19.72457 -132.43644,-56.35593 -132.43644,-56.35593 0,0 -33.81356,-73.26271 -19.72458,-73.26271 14.08899,0 132.43644,73.26271 138.07204,33.81356 5.63559,-39.44915 19.72457,-169.0678 19.72457,-169.0678 0,0 28.17797,-25.36017 -28.17796,-19.72457 -56.35593,5.63559 -95.80509,11.27118 -95.80509,11.27118 l 42.26695,-87.35169 8.45339,-28.177968";
  /> </svg>
final String SVG_PATH = "M 42.266949,70.444915 C 87.351695,30.995763 104.25847,28.177966 104.25847,28.177966 l 87.3517,36.631356 8.45339,14.088983 L 166.25,104.25847 50.720339,140.88983 c 0,0 -45.0847458,180.33898 -39.449153,194.42797 5.635594,14.08898 67.627119,183.15678 67.627119,183.15678 l 16.90678,81.7161 c 0,0 98.622885,19.72457 115.529665,22.54237 16.90678,2.8178 70.44491,-22.54237 78.8983,-33.81356 8.45339,-11.27118 76.08051,-107.07627 33.81356,-126.80085 -42.26695,-19.72457 -132.43644,-56.35593 -132.43644,-56.35593 0,0 -33.81356,-73.26271 -19.72458,-73.26271 14.08899,0 132.43644,73.26271 138.07204,33.81356 5.63559,-39.44915 19.72457,-169.0678 19.72457,-169.0678 0,0 28.17797,-25.36017 -28.17796,-19.72457 -56.35593,5.63559 -95.80509,11.27118 -95.80509,11.27118 l 42.26695,-87.35169 8.45339,-28.177968"; ViewAnimator.animate(view).svgPath(SVG_PATH).repeatCount(3).start();

Download

Add into your build.gradle

compile 'com.github.florent37:viewanimator:1.0.5'

Community

Looking for contributors, feel free to fork !

Credits

Author: Florent Champigny
Contributor: ???(liyujiang)

License

Copyright 2015 florent37, Inc.  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. 

Resources

A really simple library that help you to display a custom toast with many colors (for success, warning, danger, info, dark, light, primary, etc.), or with rounded corners, or event with image.

Sample app showcases the MVP pattern and Uncle Bob Martin's Clean Architecture approach.

A library that enables Currying functions in Java (using RxJava2 interfaces), compatible with Java 7.

Put some bubble in your tabs and give your apps a supa fresh style!

Simple yet powerful skeleton animation for all view in android.

CursorMock is a library for Android that helps testing SQLite related code without need to create testing databases, managing database connections, etc in/for testing environment. CursorMock gives ability to build a Cursor in a fast and reliable way from manually provided values or from data objects.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes