一個流暢的Android動畫庫 - ViewAnimator
一個流暢的Android動畫庫 - ViewAnimator
Usage
Animate multiple view from one method
ViewAnimator
.animate(image)
.translationY(-1000, 0)
.alpha(0,1)
.andAnimate(text)
.dp().translationX(-20, 0)
.descelerate()
.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();Download
Add into your build.gradle
compile 'com.github.florent37:viewanimator:1.0.0@aar'
compile 'com.nineoldandroids:library:2.4.0'Community
Looking for contributors, feel free to fork !
Dependencies
NineOldAndroid : Android library for using the Honeycomb (Android 3.0) animation API on all versions of the platform back to 1.0!
Credits
Author: Florent Champigny
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.
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!


