Tutorial step by step with free source code: how to zoom photo with scale animation on Image View in Android Studio version 1.5.1.

Create New Project with Application name: Zoom photo; Minimum SDK: API 10 – Android 2.3.3 (Gingerbread).

Add a picture from your computer in drawable folder, with name: photo.jpg.

Create an ImageView in activity_main.xml and display the image:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
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.example.toyo.zoomphoto.MainActivity">
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        android:src="@drawable/photo" />
</RelativeLayout>

In res folder Create New Directory with name: anim.

In anim Directory create New XML with name: zoom and complete the code:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
    <scale
        android:duration="3000"
        android:fromXScale="0.2"
        android:fromYScale="0.2"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toXScale="1.0"
        android:toYScale="1.0"
        android:repeatMode="reverse"
        android:repeatCount="infinite"/>
</set>

Complete the code in MainActivity.java:

package com.example.toyo.zoomphoto;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
        final ImageView zoom = (ImageView) findViewById(R.id.imageView);
        final Animation zoomAnimation = AnimationUtils.loadAnimation(this, R.anim.zoom);
        zoom.startAnimation(zoomAnimation);
}
}

Run your app and see final result: photo is zooming in and out, infinitely.

Tutorial how to zoom photo on ImageView in Android Studio 1.5.1

See video tutorial:

Check next tutorials to learn all about Android.
For further questions leave a message.

5 Comments

You can follow any responses to this entry through the RSS 2.0 feed.

hi my friend,
I am a beginner. I created an app showing a country map and I want to zoom in/out the map, can you help on that?
thanks a lot

    Hi my friend,
    Can I know whether you already have the answer or not. I also building an apps which is to zoom in/out of the image. hope you can help me too. Thanks friend 🙂

Congratulations! I loved the easy teaching to follow and understand!
Already thanks.

Will you please describe the attributes you have used in this, because i m a beginner in android.

Hello Sir,
I’m new android developer.
i like your tutorial and i follow you.
thank you so much…

sir, please add new tutorial in “GridGallaryView using Adapter”
i hope you will reply me.
thank you.

Leave a Reply

Your email address will not be published. Required fields are marked *

Blue Captcha Image Refresh

*