AnimationDrawable监听播放结束及ImageSwitcher动画图片切换,带动画

本文介绍了如何在Android中使用AnimationDrawable监听动画播放结束,并结合ImageSwitcher实现图片切换效果。通过示例代码展示了如何设置动画、处理滑动事件以及在不同场景下启动动画的注意事项。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

mimRepaymentProgress.setBackground(ad);

ad.start();

handler.sendEmptyMessageDelayed(100, 1500);

isOverdue = true;

} else {

mtvRepaymentStatement.setText(R.string.home_prepayment);

mllOverdue.setVisibility(View.GONE);

for (int i = 0; i < 15 - productInfo.getData().getOrderDetail().getRepayDay(); i++) {

ad.addFrame(getResources().getDrawable(res.get(i)), 100);

}

ad.setOneShot(true);

mimRepaymentProgress.setBackground(ad);

ad.start();

}

}

Handler handler = new Handler(new Handler.Callback() {

@Override

public boolean handleMessage(Message msg) {

switch (msg.what) {

case 100:

AnimationSet animationSet = new AnimationSet(true);

ScaleAnimation scaleAnimation = new ScaleAnimation(0.5f, 1, 0.5f, 1,

Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);

scaleAnimation.setDuration(100);

animationSet.addAnimation(scaleAnimation);

//启动动画

mllOverdueDay.startAnimation(animationSet);

mllOverdueDay.setVisibility(View.VISIBLE);

break;

}

return false;

}

});

当启动其他Fragment,Activity并未对本界面进行销毁时AnimationDrawable会停止(回到第一张图片),

返回本界面是可以再次ad.start();//启动动画handler.sendEmptyMessageDelayed(100, 1400);//1400整个动画所需时间,(如有多次启动动画的代码需要handler.removeMessages(100);

<ImageSwitcher

android:id="@+id/image_SwitcherTop"

android:layout_width=“match_parent”

android:layout_height=“250dp”

android:layout_centerHorizontal=“true”

android:layout_marginTop=“80dp” />

imgIds = new int[]{R.mipmap.icon_splash_top_1, R.mipmap.icon_splash_top_2,

R.mipmap.icon_splash_top_3};

imageSwitcherTop.setFactory(this);

imageSwitcherTop.setImageResource(imgIds[currentPosition % imgIds.length]);

extends BaseActivity implements ViewSwitcher.ViewFactory

@Override

public View makeView() {

return new ImageView(this);

}

左右滑动事件监听(可以添加动画效果)

@Override

public boolean onTouchEvent(MotionEvent event) {

//继承了Activity的onTouchEvent方法,直接监听点击事件

if (event.getAction() == MotionEvent.ACTION_DOWN) {

//当手指按下的时候

downx = event.getX();

}

if (event.getAction() == MotionEvent.ACTION_UP) {

//当手指离开的时候

upx = event.getX();

if(firstTime){

if (downx > upx && currentPosition < imgIds.length - 1) {

currentPosition++;

imageSwitcherTop.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.right_in));

imageSwitcherTop.setOutAnimation(

《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》

【docs.qq.com/doc/DSkNLaERkbnFoS0ZF】 完整内容开源分享

AnimationUtils.loadAnimation(this, R.anim.lift_out));

imageSwitcherTop.setImageResource(imgIds[currentPosition % imgIds.length]);

} else if (upx > downx && currentPosition > 0) {

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值