In this tutorial, I'll show you how to implement an image previewing effect zoom in android apps. Applying the zoom effect on Android ImageView images is not too easy, it's a bit tricky. You can find the same project type on the android developer site, in the Building Application with Graphic and Animation topics.
When you touch or click on the image start zoom, this type of animation zooming can be used in photo gallery. To create a zoom in image in an XML file layout, two ImageView components are used; one for thumbnails and more for big picture. A great picture of the image is for full screen size and thumbnail images for thumbnail sizes.
Android Example: How to Apply Magnification Effect in Android Image View Image
Here you will find all the code needed to make a zoom in an android picture display image. There are only two important files; one XML file layout and the other is a java activity file and then you must add one image in your projects drawable folder.
1. Open your project’s build.gradle ( Module : app ) file.
2. Please add the code below in your build.gradle (Module: app) file.
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.github.chrisbanes:PhotoView:1.3.0'
3. Screenshot of build.gradle ( Module : app ) file after adding above code.
4. Now open build.gradle(Project) .
5. Add below code inside it :
allprojects {
repositories {
maven { url "https://jitpack.io" }
}
}
6. Screenshot after adding the code above:
Here you go now the next step is to start coding.
How to Add Pinch Effect Zoom MultiTouch to ImageView on Android
Code for MainActivity.java file.
package com.android_examples.androidpinchzoom_android_examplescom;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import uk.co.senab.photoview.PhotoViewAttacher;
public class MainActivity extends AppCompatActivity {
ImageView imageView ;
PhotoViewAttacher photoViewAttacher ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = (ImageView)findViewById(R.id.imageView);
Drawable drawable = getResources().getDrawable(R.drawable.sample_zoom_image);
imageView.setImageDrawable(drawable);
photoViewAttacher = new PhotoViewAttacher(imageView);
photoViewAttacher.update();
}
}
Code for activity_main.xml layout file.
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.android_examples.androidpinchzoom_android_examplescom.MainActivity"
android:background="#FFF9C4">
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/sample_zoom_image"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:id="@+id/imageView" />
Screenshots:
Also Read More :
- Source Code Project Android Studio Free "Ram Booster Cleaner Memory and Junk versi 1.0"
- Source Code Project Eclipse Super Fly Bird Adventure Android Game
- source code game android 2D Pirate Adventures - pirates game Project Android Studio 2018
- Free Download PHP Script Source Code Affiliate Boss Versi 1.0 Price Comparison
- Source Code Super Dog Flappybird Reskin Project Android Studio integrated Admob