Android ImageView Zoom-in and Zoom-out Continuously

前端 未结 3 722
误落风尘
误落风尘 2021-02-07 11:23

Is there any way to Zoom-in and Zoom-out an ImageView continuously in Android. I tried using the below code, but only one of the Zoom function is working.

相关标签:
3条回答
  • 2021-02-07 11:36

    You can use something like below and as Sanket mentioned

    Zommin.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="5000"
            android:fromXScale="1"
            android:fromYScale="1"
            android:pivotX="50%"
            android:pivotY="50%"
            android:toXScale="1.5"
            android:toYScale="1.5"
            >
        </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="5000"
            android:fromXScale="1.5"
            android:fromYScale="1.5"
            android:pivotX="50%"
            android:pivotY="50%"
            android:toXScale="1"
            android:toYScale="1" >
        </scale>
    
    </set>
    

    And the code :

    zoomin.setAnimationListener(new Animation.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) {
                    imageView.startAnimation(zoomout);
    
                }
            });
    
    0 讨论(0)
  • 2021-02-07 11:52

    simply use in your animation xml:

     android:repeatMode="restart"
        android:repeatCount="infinite"
    
    0 讨论(0)
  • 2021-02-07 11:55

    use this instead of thread

     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); 
    
            }
        });
    

    and

     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); 
    
            }
        });
    
    0 讨论(0)
提交回复
热议问题