通过两个动画相互调用来达到无限循环的目的,同时这两个动画也实现了竖直滚动的效果
top=new TranslateAnimation(Animation.RELATIVE_TO_SELF,0f,Animation.RELATIVE_TO_SELF,0f,Animation.RELATIVE_TO_SELF,0f,Animation.RELATIVE_TO_SELF,-1f); top.setDuration(500); top.setStartOffset(3000); ead=new TranslateAnimation(Animation.RELATIVE_TO_SELF,0f,Animation.RELATIVE_TO_SELF,0f,Animation.RELATIVE_TO_SELF,1f,Animation.RELATIVE_TO_SELF,0f); ead.setDuration(500);
先实例化两个动画,一个从当前位置往上滚动,一个从当前位置的下方移动上来当前位置。
top.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { clearAnimation(); cu++; if (listString != null) { if (cu == listString.size() || cu > listString.size()) cu = 0; } setText(listString.get(cu)); startAnimation(ead); } @Override public void onAnimationRepeat(Animation animation) { } });
动画监听,往上这个动画完了之后,替换文本,同时执行另外一个动画
ead.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { clearAnimation(); startAnimation(top); } @Override public void onAnimationRepeat(Animation animation) { } });
这个比较简单,动画执行完直接执行往上的动画即可