下面列出了android.view.animation.TranslateAnimation#setStartOffset() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void init() {
widthScale(0.95f);
/** LayoutAnimation */
TranslateAnimation animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF,
0f, Animation.RELATIVE_TO_SELF, 6f, Animation.RELATIVE_TO_SELF, 0);
animation.setInterpolator(new DecelerateInterpolator());
animation.setDuration(350);
animation.setStartOffset(150);
mLac = new LayoutAnimationController(animation, 0.12f);
mLac.setInterpolator(new DecelerateInterpolator());
}
/**
* 从左侧进入,并带有弹性的动画
*
* @return
*/
public static AnimationSet getAnimationSetFromLeft() {
AnimationSet animationSet = new AnimationSet(true);
TranslateAnimation translateX1 = new TranslateAnimation(RELATIVE_TO_SELF, -1.0f, RELATIVE_TO_SELF, 0.1f,
RELATIVE_TO_SELF, 0, RELATIVE_TO_SELF, 0);
translateX1.setDuration(300);
translateX1.setInterpolator(new DecelerateInterpolator());
translateX1.setStartOffset(0);
TranslateAnimation translateX2 = new TranslateAnimation(RELATIVE_TO_SELF, 0.1f, RELATIVE_TO_SELF, -0.1f,
RELATIVE_TO_SELF, 0, RELATIVE_TO_SELF, 0);
translateX2.setStartOffset(300);
translateX2.setInterpolator(new DecelerateInterpolator());
translateX2.setDuration(50);
TranslateAnimation translateX3 = new TranslateAnimation(RELATIVE_TO_SELF, -0.1f, RELATIVE_TO_SELF, 0f,
RELATIVE_TO_SELF, 0, RELATIVE_TO_SELF, 0);
translateX3.setStartOffset(350);
translateX3.setInterpolator(new DecelerateInterpolator());
translateX3.setDuration(50);
AlphaAnimation alphaAnimation = new AlphaAnimation(0.5f, 1.0f);
alphaAnimation.setDuration(400);
alphaAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
animationSet.addAnimation(translateX1);
animationSet.addAnimation(translateX2);
animationSet.addAnimation(translateX3);
//animationSet.addAnimation(alphaAnimation);
animationSet.setDuration(400);
return animationSet;
}
/**
* 从右侧进入,并带有弹性的动画
*
* @return
*/
public static AnimationSet getAnimationSetFromRight() {
AnimationSet animationSet = new AnimationSet(true);
TranslateAnimation translateX1 = new TranslateAnimation(RELATIVE_TO_SELF, 1.0f, RELATIVE_TO_SELF, -0.1f,
RELATIVE_TO_SELF, 0, RELATIVE_TO_SELF, 0);
translateX1.setDuration(300);
translateX1.setInterpolator(new DecelerateInterpolator());
translateX1.setStartOffset(0);
TranslateAnimation translateX2 = new TranslateAnimation(RELATIVE_TO_SELF, -0.1f, RELATIVE_TO_SELF, 0.1f,
RELATIVE_TO_SELF, 0, RELATIVE_TO_SELF, 0);
translateX2.setStartOffset(300);
translateX2.setInterpolator(new DecelerateInterpolator());
translateX2.setDuration(50);
TranslateAnimation translateX3 = new TranslateAnimation(RELATIVE_TO_SELF, 0.1f, RELATIVE_TO_SELF, 0f,
RELATIVE_TO_SELF, 0, RELATIVE_TO_SELF, 0);
translateX3.setStartOffset(350);
translateX3.setInterpolator(new DecelerateInterpolator());
translateX3.setDuration(50);
AlphaAnimation alphaAnimation = new AlphaAnimation(0.5f, 1.0f);
alphaAnimation.setDuration(400);
alphaAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
animationSet.addAnimation(translateX1);
animationSet.addAnimation(translateX2);
animationSet.addAnimation(translateX3);
animationSet.addAnimation(alphaAnimation);
animationSet.setDuration(400);
return animationSet;
}
/**
* 从底部进入
*
* @return
*/
public static AnimationSet getAnimationSetFromBottom() {
AnimationSet animationSet = new AnimationSet(true);
TranslateAnimation translateX1 = new TranslateAnimation(RELATIVE_TO_SELF, 0, RELATIVE_TO_SELF, 0,
RELATIVE_TO_SELF, 2.5f, RELATIVE_TO_SELF, 0);
translateX1.setDuration(400);
translateX1.setInterpolator(new DecelerateInterpolator());
translateX1.setStartOffset(0);
animationSet.addAnimation(translateX1);
animationSet.setDuration(400);
return animationSet;
}
/**
* 从顶部进入
*
* @return
*/
public static AnimationSet getAnimationSetFromTop() {
AnimationSet animationSet = new AnimationSet(true);
TranslateAnimation translateX1 = new TranslateAnimation(RELATIVE_TO_SELF, 0, RELATIVE_TO_SELF, 0,
RELATIVE_TO_SELF, -2.5f, RELATIVE_TO_SELF, 0);
translateX1.setDuration(400);
translateX1.setInterpolator(new DecelerateInterpolator());
translateX1.setStartOffset(0);
animationSet.addAnimation(translateX1);
animationSet.setDuration(400);
return animationSet;
}
private static void ApplyHorizontalScrollAnimation(View view, boolean left, int speed) {
float sign = left ? 1f : -1f;
AnimationSet animationSet = new AnimationSet(true);
animationSet.setRepeatCount(Animation.INFINITE);
animationSet.setRepeatMode(Animation.RESTART);
TranslateAnimation move = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, sign * 0.70f,
Animation.RELATIVE_TO_PARENT, sign * -0.70f, Animation.RELATIVE_TO_PARENT, 0,
Animation.RELATIVE_TO_PARENT, 0);
move.setStartOffset(0);
move.setDuration(speed);
move.setFillAfter(true);
animationSet.addAnimation(move);
view.startAnimation(animationSet);
}
private void init() {
widthScale(0.95f);
/** LayoutAnimation */
TranslateAnimation animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF,
0f, Animation.RELATIVE_TO_SELF, 6f, Animation.RELATIVE_TO_SELF, 0);
animation.setInterpolator(new DecelerateInterpolator());
animation.setDuration(350);
animation.setStartOffset(150);
mLac = new LayoutAnimationController(animation, 0.12f);
mLac.setInterpolator(new DecelerateInterpolator());
}
private void init() {
widthScale(0.95f);
/** LayoutAnimation */
TranslateAnimation animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF,
0f, Animation.RELATIVE_TO_SELF, 6f, Animation.RELATIVE_TO_SELF, 0);
animation.setInterpolator(new DecelerateInterpolator());
animation.setDuration(350);
animation.setStartOffset(150);
mLac = new LayoutAnimationController(animation, 0.12f);
mLac.setInterpolator(new DecelerateInterpolator());
}
private void initIconAnimation(View view, int delay) {
TranslateAnimation ta=new TranslateAnimation(Animation.RELATIVE_TO_SELF,0f,Animation.RELATIVE_TO_SELF,0f,
Animation.RELATIVE_TO_PARENT,1f,Animation.RELATIVE_TO_SELF,0f);
ta.setDuration(1000);
ta.setStartOffset(delay);
ta.setFillAfter(true);
view.startAnimation(ta);
}
private void startAnimation(){
TranslateAnimation upUp = new TranslateAnimation(TranslateAnimation.RELATIVE_TO_SELF,0,TranslateAnimation.RELATIVE_TO_SELF,0,
TranslateAnimation.RELATIVE_TO_SELF,0,TranslateAnimation.RELATIVE_TO_SELF,-1);
upUp.setDuration(1000);
TranslateAnimation upDown = new TranslateAnimation(TranslateAnimation.RELATIVE_TO_SELF,0,TranslateAnimation.RELATIVE_TO_SELF,0,
TranslateAnimation.RELATIVE_TO_SELF,0,TranslateAnimation.RELATIVE_TO_SELF,1);
upDown.setDuration(1000);
upDown.setStartOffset(1000);
//组合动画
AnimationSet upSet = new AnimationSet(false);
//将上面的动画添加到组合动画
upSet.addAnimation(upUp);
upSet.addAnimation(upDown);
//控件开启动画
iv_up.startAnimation(upSet);
TranslateAnimation downDown = new TranslateAnimation(TranslateAnimation.RELATIVE_TO_SELF,0,TranslateAnimation.RELATIVE_TO_SELF,0,
TranslateAnimation.RELATIVE_TO_SELF,0,TranslateAnimation.RELATIVE_TO_SELF,1);
downDown.setDuration(1000);
TranslateAnimation downUp = new TranslateAnimation(TranslateAnimation.RELATIVE_TO_SELF,0,TranslateAnimation.RELATIVE_TO_SELF,0,
TranslateAnimation.RELATIVE_TO_SELF,0,TranslateAnimation.RELATIVE_TO_SELF,-1);
downUp.setDuration(1000);
downUp.setStartOffset(1000);
AnimationSet downSet = new AnimationSet(false);
downSet.addAnimation(downDown);
downSet.addAnimation(downUp);
iv_down.startAnimation(downSet);
}
private void init() {
widthScale(0.95f);
/** LayoutAnimation */
TranslateAnimation animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF,
0f, Animation.RELATIVE_TO_SELF, 6f, Animation.RELATIVE_TO_SELF, 0);
animation.setInterpolator(new DecelerateInterpolator());
animation.setDuration(350);
animation.setStartOffset(150);
mLac = new LayoutAnimationController(animation, 0.12f);
mLac.setInterpolator(new DecelerateInterpolator());
}
/**
* Creates animation for the gallery and homePage Icons with up direction.
*/
public void createIconUpAnimation(float dy, int delay) {
iconUpAnimation = new TranslateAnimation(0, 0, 0, (-(scale * 67.3f) + 0.5f - (dy * scale)) * iconDirection);
iconUpAnimation.setDuration(250);
iconUpAnimation.setFillAfter(false);
iconUpAnimation.setStartOffset(delay);
iconUpAnimation.setAnimationListener(iconUpAnimationListener);
}
/**
* Creates animation for the gallery and homePage Icons with up direction.
*/
public void createIconUpAnimation(float dy, int delay) {
iconUpAnimation = new TranslateAnimation(0, 0, 0, (-(scale * 67.3f) + 0.5f - (dy * scale)) * iconDirection);
iconUpAnimation.setDuration(250);
iconUpAnimation.setFillAfter(false);
iconUpAnimation.setStartOffset(delay);
iconUpAnimation.setAnimationListener(iconUpAnimationListener);
}
/**
* Creates animation for the gallery and gallery, homePage and trailer Icons with up direction.
*/
public void createIconUpAnimation(float dy, int delay) {
iconUpAnimation = new TranslateAnimation(0, 0, 0, (-(scale * 67.3f) + 0.5f - (dy * scale)) * iconDirection);
iconUpAnimation.setDuration(250);
iconUpAnimation.setFillAfter(false);
iconUpAnimation.setStartOffset(delay);
iconUpAnimation.setAnimationListener(iconUpAnimationListener);
}