Android Imageview Zoom-In and Zoom-Out

Android ImageView Zoom-in and Zoom-Out

Make two java classes

Zoom class

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;

public class Zoom extends View {

private Drawable image;
ImageButton img,img1;
private int zoomControler=20;

public Zoom(Context context){
super(context);

image=context.getResources().getDrawable(R.drawable.j);
//image=context.getResources().getDrawable(R.drawable.icon);

setFocusable(true);
}

@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);

//here u can control the width and height of the images........ this line is very important
image.setBounds((getWidth()/2)-zoomControler, (getHeight()/2)-zoomControler, (getWidth()/2)+zoomControler, (getHeight()/2)+zoomControler);
image.draw(canvas);
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {

if(keyCode==KeyEvent.KEYCODE_DPAD_UP){
// zoom in
zoomControler+=10;
}
if(keyCode==KeyEvent.KEYCODE_DPAD_DOWN){
// zoom out
zoomControler-=10;
}
if(zoomControler<10){
zoomControler=10;
}

invalidate();
return true;
}
}

make second class

import android.app.Activity;
import android.os.Bundle;

public class Zoomexample extends Activity {
/** Called when the activity is first created. */

@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(new Zoom(this));
}
}

ImageView zooming in android through code

Below are the options available for implementing zoom in-out effect in android Imageview.

  1. How to implement zoom effect for image view in android?
  2. Android imageView Zoom-in and Zoom-Out
  3. https://github.com/chrisbanes/PhotoView

Zoom An Image ( Android Studio )

You can use this library. This is the perfect library according to your requirement. You can also apply zoom in/out for video.

https://github.com/natario1/ZoomLayout

Android ImageView Zoom-in and Zoom-out Continuously

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

}
});

on touch of image, image view to fullscreen and zoom should work

There are some simple steps you should follow.

  1. Create one full-screen Activitywith ImageView only.

  2. You need to implement library for Pinch to Zoom In/Zoom Out Images. Through which you can zoom In/Out your Imageview.

  3. By Clicking on Imageview Start that Activity and Finish on onBackPress()

There are some of the examples of library you can use.

https://github.com/martinwithaar/PinchToZoom

https://github.com/jsibbold/zoomage

How to zoom in and return with animation android?

Animation is outdated(Animation vs Animator). Use ValueAnimator:

        final ValueAnimator anim = ValueAnimator.ofFloat(1f, 1.5f);
anim.setDuration(1000);
anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
image.setScaleX((Float) animation.getAnimatedValue());
image.setScaleY((Float) animation.getAnimatedValue());
}
});
anim.setRepeatCount(1);
anim.setRepeatMode(ValueAnimator.REVERSE);
anim.start();

Sample Image



Related Topics



Leave a reply



Submit