滚动通知(中奖公告)

通过两个动画相互调用来达到无限循环的目的,同时这两个动画也实现了竖直滚动的效果

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) {

    }
});

这个比较简单,动画执行完直接执行往上的动画即可

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值