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.
- How to implement zoom effect for image view in android?
- Android imageView Zoom-in and Zoom-Out
- 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.
Create one full-screen Activitywith
ImageView
only.You need to implement library for Pinch to Zoom In/Zoom Out Images. Through which you can zoom In/Out your Imageview.
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();
Related Topics
How to Implement a Viewpager With Different Fragments/Layouts
Focusable Edittext Inside Listview
Why Not Use Always Android:Configchanges="Keyboardhidden|Orientation"
How to Define Dimens.Xml For Every Different Screen Size in Android
How to Connect to My Http://Localhost Web Server from Android Emulator
How to Set the Part of the Text View Is Clickable
What Is Android:Weightsum in Android, and How Does It Work
Key Hash For Android-Facebook App
Best Practice For Storing and Protecting Private API Keys in Applications
What Is the Main Purpose of Settag() Gettag() Methods of View
Difference Between "@Id/" and "@+Id/" in Android
Adding a Library/Jar to an Eclipse Android Project
Start Activity from Service in Android
How to Send a Json Object Over Request With Android
Handle Textview Link Click in My Android App