splash = (RelativeLayout)findViewById(R.id.splash);
//旋转动画
RotateAnimation rotateAnimation = new RotateAnimation(0,360,
Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
rotateAnimation.setDuration(2000);
rotateAnimation.setFillAfter(true);
//缩放动画
ScaleAnimation scaleAnimation = new ScaleAnimation(0,1,0,1,
Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
scaleAnimation.setDuration(2000);
scaleAnimation.setFillAfter(true);
//渐变动画
AlphaAnimation alphaAnimation = new AlphaAnimation(0.2f,1.0f);
alphaAnimation.setDuration(2000);
alphaAnimation.setFillAfter(true);
//平移动画
TranslateAnimation translateAnimation = newTranslateAnimation (0,0,100,100);
translateAnimation.setDuration(2000);
translateAnimation.setFillAfter(true);
//动画集合
AnimationSet animationSet = new AnimationSet(true);
animationSet.addAnimation(rotateAnimation);
animationSet.addAnimation(scaleAnimation);
animationSet.addAnimation(alphaAnimation);
animationSet.addAnimation(translateAnimation);
//启动动画
plash.startAnimation(animationSet);
//res/anim/anim/layout_anim.xml <layoutAnimation xmlns:android=” http://schemas.android.com/apk/res/android” android:delay=”0.1” //动画延迟时间为0.1*T,本例为100ms android:animationOrder=”normal” //子元素的播放动画顺序为顺序,也有reverse以及random android: animation=” @anim/layout_anim_item”/> //res/anim/anim/layout_anim_item.xml <?xml version=”1.0” encoding=”utf-8”?> <set xmlns:android=”http://schemas.android.com/apk/res/android” animation:duration=”200” //每个子元素的动画周期T animation:interpolator=”@android:anim/accelerate_ interpolator” //指定插值器 animation:shareInterpolator=”true”> //表示所有子元素共享该插值器 <alpha android:fromAlpha=”0.2” android: toAlpha =”1.0”/> <translate android:fromXDelta=”100” android: toXDelta =”0”/> </set>
//res/anim/tran_in <?xml version="1.0" encoding="utf-8"?> <translate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="500" //表示从屏幕100%的位置开始,因此tran_out当然是toXDelta="-100%p",其他不变 android:fromXDelta="100%p" android:fromYDelta="0" android:toXDelta="0" android:toYDelta="0" > </translate>
//res/drawable/myanimation.xml <?xml version=”1.0” encoding=”utf-8”?> <animation-list xmlns:android=”http://schemas.android.com/apk/res/android” animation:oneshot=”false” > //false为循环播放,true为类似于View动画的setFillAfter效果 <item android: drawable =”@ drawable/ drawable 1” android:duration=” 200”> <item android: drawable =”@ drawable/ drawable 2” android:duration=” 200”> </animation-list> //在代码里加载动画设置并启动动画 view.setBackgroundResource(R.drawable.myanimation.xml); (AnimationDrawable)view.getBackground.start();
view.setTranslationX(x);//3.0以后 ViewHelper.setTranslationX(view,x);//3.0以前通过NineOldAndroid库实现
ValueAnimator只定义和执行动画流程,并没有直接操作属性值的逻辑,需要添加动画更新的监听,并在onAnimationUpdate()中执行自定义的动画逻辑。
[java] view plain copy 在CODE上查看代码片派生到我的代码片
ValueAnimator animator = ValueAnimator.ofInt(1, 100); //定义动画,相当于1秒内数100个数
animator.addUpdateListener(new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation){
float fraction = animation.getAnimatedFraction();//动画进度值0-1
//整型估值器帮我们计算了start+(end-strat)*fraction,并设置给控件的宽度
view.getLayoutParams().width = new IntEvaluator().evaluate(fraction,start,end) //不需要set方法
view.requestLayout();
}
});
animator.setDuration(1000).start();
//x轴方向缩放的例子 ObjectAnimator animator = ObjectAnimator.ofFloat(view,”scaleX”,2.0f); animator.setDuration(1000); animator.setStartDelay(1000); animator.start();
ViewWrapper wrapper = new ViewWrapper(view);
ObjectAnimator.ofInt(view,”width”,200).setDuration(1000).start();
private static class ViewWrapper{
private View myView;
public ViewWrapper(View view){
myView = view;
}
public int getWidth(){
return myView.getLayoutParams().width;
}
public int setWidth(int width){
myView.getLayoutParams().width = width;
myView.requestLayout();
}
}
//x轴方向缩放的例子,效果同3.3 ViewPropertyAnimation.animate(view).scaleX(2.0f).setDuration(1000) .setInterpolator(new OvershootInterpolator()) .setStartDelay(1000).start();
ObjectAnimator objectAnimator1= ObjectAnimator.ofFloat(view, "alpha", 1.0f, 0f); ObjectAnimator objectAnimator2= ObjectAnimator.ofFloat(view, "translationY", 0f, 30f); ObjectAnimator objectAnimator3= ObjectAnimator.ofFloat(view, "translationX", 0f, 30f); AnimatorSet animatorSet = new AnimatorSet(); animatorSet.setDuration(5000); animatorSet.setInterpolator(new LinearInterpolator()); // animatorSet.playTogether(objectAnimator1, objectAnimator2. objectAnimator3); //三个动画同时执行 // 12同时执行,3接着执行 animatorSet.play(objectAnimator1).with(objectAnimator2); animatorSet.play(objectAnimator3).after(objectAnimator2); animatorSet.start();
public class AccelerateDecelerateInterpolator extends BaseInterpolator
implements NativeInterpolatorFactory {
......
public float getInterpolation(float input) {
return (float)(Math.cos((input + 1) * Math.PI) / 2.0f) + 0.5f;
}
......
}
//监听动画完成
animationSet.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {}
@Override
public void onAnimationEnd(Animation animation) {}
@Override
public void onAnimationRepeat(Animation animation) {}
@Override
public void onAnimationCancel(Animation animation) {}
});
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有