AnimationDrawable监听播放结束及ImageSwitcher动画图片切换,带动画
2017-05-09 11:37
1476 查看
//java代码动态加载动画 或者res/anim/中加载
当启动其他Fragment,Activity并未对本界面进行销毁时AnimationDrawable会停止(回到第一张图片),
返回本界面是可以再次ad.start();//启动动画handler.sendEmptyMessageDelayed(100, 1400);//1400整个动画所需时间,(如有多次启动动画的代码需要handler.removeMessages(100);
左右滑动事件监听(可以添加动画效果)
ImageSwitcher动画图片切换
左右滑动事件监听(可以添加动画效果)
左右滑动事件监听(可以添加动画效果)
private void setRepaymentDate(NewProductInfoBean productInfo) { ArrayList<Integer> res = new ArrayList<>(); res.add(R.mipmap.day_left_1); res.add(R.mipmap.day_left_2); res.add(R.mipmap.day_left_3); res.add(R.mipmap.day_left_4); res.add(R.mipmap.day_left_5); res.add(R.mipmap.day_left_6); res.add(R.mipmap.day_left_7); res.add(R.mipmap.day_left_8); res.add(R.mipmap.day_left_9); res.add(R.mipmap.day_left_10); res.add(R.mipmap.day_left_11); res.add(R.mipmap.day_left_12); res.add(R.mipmap.day_left_13); res.add(R.mipmap.day_left_14); res.add(R.mipmap.over_due); mllOverdueDay.setVisibility(View.GONE); ad = new AnimationDrawable(); isOverdue = false; if (productInfo.getData().getOrderDetail().getStatus() == 17)//逾期 { handler.removeMessages(100); mllOverdue.setVisibility(View.VISIBLE); for (int i = 0; i < res.size(); i++) { ad.addFrame(getResources().getDrawable(res.get(i)), 100); } ad.setOneShot(true); 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(AnimationUtils.loadAnimation(this, R.anim.lift_out)); imageSwitcherTop.setImageResource(imgIds[currentPosition % imgIds.length]); } else if (upx > downx && currentPosition > 0) { currentPosition--; imageSwitcherTop.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.left_in)); imageSwitcherTop.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.right_out)); imageSwitcherTop.setImageResource(imgIds[currentPosition % imgIds.length]); } tvTrynow.setVisibility(currentPosition == (imgIds.length - 1) ? View.VISIBLE : View.GONE); setImageBackground(currentPosition); } } return super.onTouchEvent(event); }
ImageSwitcher动画图片切换
<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(AnimationUtils.loadAnimation(this, R.anim.lift_out)); imageSwitcherTop.setImageResource(imgIds[currentPosition % imgIds.length]); } else if (upx > downx && currentPosition > 0) { currentPosition--; imageSwitcherTop.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.left_in)); imageSwitcherTop.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.right_out)); imageSwitcherTop.setImageResource(imgIds[currentPosition % imgIds.length]); } tvTrynow.setVisibility(currentPosition == (imgIds.length - 1) ? View.VISIBLE : View.GONE); setImageBackground(currentPosition); } } return super.onTouchEvent(event); }
<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(AnimationUtils.loadAnimation(this, R.anim.lift_out)); imageSwitcherTop.setImageResource(imgIds[currentPosition % imgIds.length]); } else if (upx > downx && currentPosition > 0) { currentPosition--; imageSwitcherTop.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.left_in)); imageSwitcherTop.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.right_out)); imageSwitcherTop.setImageResource(imgIds[currentPosition % imgIds.length]); } tvTrynow.setVisibility(currentPosition == (imgIds.length - 1) ? View.VISIBLE : View.GONE); setImageBackground(currentPosition); } } return super.onTouchEvent(event); }
相关文章推荐
- Android学习笔记进阶十一图片动画播放(AnimationDrawable)
- Android学习笔记进阶十一图片动画播放(AnimationDrawable)
- 图片动画播放(AnimationDrawable)
- Android学习笔记进阶十一图片动画播放(AnimationDrawable)
- Android图片动画播放(AnimationDrawable)
- Android学习笔记进阶十一图片动画播放(AnimationDrawable)
- 自定义AnimationDrawable动画播放完监听
- 【Android 开发】:UI控件之 ImageSwitcher 图片切换控件的使用
- AnimationDrawable动画最后一贞结束侦听。
- AnimationDrawable android 动画 初始化界面播放
- ImageSwitcher自定意效果+定时切换图片
- 解决使用AnimationDrawable无法播放动画的问题
- Android UI控件之ImageSwitcher(图片切换)
- iPhone 如何使用UIImageView播放动画,并停留在之后一张图片并添加播放结束时的事件
- 实现UIImageView播放图片动画结束通知
- 解决使用AnimationDrawable无法播放动画的问题
- 实现UIImageView播放图片动画结束通知的demo
- Animation动画开始、结束、重复事件监听
- Android学习笔记26:图片切换控件ImageSwitcher的使用
- Android学习笔记26-图片切换控件ImageSwitcher的使用