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.
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>
And the Activity
class that I've :
Animation zoomin, zoomout; //declared as public
@Override
public 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);
}
}
}
Here the zoomin
animation seems to be working fine. Is there any way to implement the zoomin
and zoomout
animation continuously???
Thanks
Pinch 2 or more fingers together or apart to adjust zoom. To zoom temporarily, quickly tap the screen 3 times and hold down your finger on the third tap. Drag your finger to move around the screen. Lift your finger to zoom out.
This example demonstrates how do I Zoom In and Zoom Out an android ImageView. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main.
In Android, Zoom Control is a class that has some set of methods that are used to control the zoom functionality. It has two buttons that are used to control the zoom functionality (ie Zoom In and Zoom Out). Zoom Control Class has been deprecated in API Version 29.
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);
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With