Android ImageView连续放大和缩小

Android ImageView连续放大和缩小,第1张

概述有没有办法在 Android中连续放大和缩小ImageView.我尝试使用下面的代码,但只有一个Zoom功能正在运行. zoomin.xml <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:fillAfter= 有没有办法在 Android中连续放大和缩小ImageVIEw.我尝试使用下面的代码,但只有一个Zoom功能正在运行.

zoomin.xml

<?xml version="1.0" enCoding="utf-8"?>    <set xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:fillAfter="true" >     <scale        xmlns:androID="http://schemas.androID.com/apk/res/androID"        androID:duration="20000"        androID:fromXScale="1"        androID:fromYScale="1"        androID:pivotX="50%"        androID:pivotY="50%"        androID:toXScale="3"        androID:toYScale="3" >    </scale></set>

zoomout.xml

<?xml version="1.0" enCoding="utf-8"?>    <set xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:fillAfter="true" >     <scale        xmlns:androID="http://schemas.androID.com/apk/res/androID"        androID:duration="20000"        androID:fromXScale="1.0"        androID:fromYScale="1.0"        androID:pivotX="50%"        androID:pivotY="50%"        androID:toXScale="0.5"        androID:toYScale="0.5" >    </scale></set>

和我的Activity类:

Animation zoomin,zoomout; //declared as public@OverrIDepublic voID onCreate(Bundle savedInstanceState) {   // animation    zoomin = AnimationUtils.loadAnimation(this,R.anim.zoomin);    zoomout = AnimationUtils.loadAnimation(this,R.anim.zoomout);    bgImage.setAnimation(zoomin);    bgImage.setAnimation(zoomout);    Thread t = new Thread(new Zoom());    t.start();}private class Zoom implements Runnable {    @OverrIDe    public voID run() {        while (true) {                          bgImage.startAnimation(zoomin);            try {                Thread.sleep(8000);            } catch (InterruptedException e) {                                    e.printstacktrace();            }                           bgImage.startAnimation(zoomout);        }    }}

这里的zoomin动画似乎工作正常.有没有办法连续实现缩放和缩小动画?

谢谢

解决方法 使用这个而不是线程
zoomin.setAnimationListener(new AnimationListener() {        @OverrIDe        public voID onAnimationStart(Animation arg0) {            // Todo auto-generated method stub        }        @OverrIDe        public voID onAnimationRepeat(Animation arg0) {            // Todo auto-generated method stub        }        @OverrIDe        public voID onAnimationEnd(Animation arg0) {            bgImage.startAnimation(zoomout);         }    });

zoomout.setAnimationListener(new AnimationListener() {        @OverrIDe        public voID onAnimationStart(Animation arg0) {            // Todo auto-generated method stub        }        @OverrIDe        public voID onAnimationRepeat(Animation arg0) {            // Todo auto-generated method stub        }        @OverrIDe        public voID onAnimationEnd(Animation arg0) {            bgImage.startAnimation(zoomin);         }    });
总结

以上是内存溢出为你收集整理的Android ImageView连续放大和缩小全部内容,希望文章能够帮你解决Android ImageView连续放大和缩小所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/web/1133138.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存