info@thistimebd.com

Tuesday 3rd of December 10:48:47pm

android zoom in out app source code free download

MainActivity.java

------------------


package com.sam.web.zoomcontrol;


import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.view.View;

import android.widget.ImageView;

import android.widget.Toast;

import android.widget.ZoomControls;


public class MainActivity extends AppCompatActivity {

    private ImageView imageView;

    private ZoomControls zoomControls;


    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);


        imageView=(ImageView) findViewById(R.id.imageViewId);

        zoomControls=(ZoomControls) findViewById(R.id.zoomControlId);


        zoomControls.setOnZoomInClickListener(new View.OnClickListener() {

            @Override

            public void onClick(View v) {

                Toast.makeText(getApplicationContext(),"Zoom in",Toast.LENGTH_SHORT).show();


                float x=imageView.getScaleX();

                float y= imageView.getScaleY();


                imageView.setScaleX((float) x+1);

                imageView.setScaleY((float) y+1);

            }

        });



        zoomControls.setOnZoomOutClickListener(new View.OnClickListener() {

            @Override

            public void onClick(View v) {

                Toast.makeText(getApplicationContext(),"Zoom out",Toast.LENGTH_SHORT).show();

                float x=imageView.getScaleX();

                float y= imageView.getScaleY();


                if(x>1 && y>1){


                    imageView.setScaleX((float) x-1);

                    imageView.setScaleY((float) y-1);


                }


            }

        });

    }

}

=====================================================================================================

activity_main.xml

----------------


<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:app="http://schemas.android.com/apk/res-auto"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:orientation="vertical"

    android:gravity="center"

    tools:context="com.sam.web.zoomcontrol.MainActivity">


<ImageView

    android:layout_marginBottom="100dp"

    android:id="@+id/imageViewId"

    android:src="@mipmap/ic_launcher"

    android:layout_width="wrap_content"

    android:layout_height="wrap_content" />


    <ZoomControls

        android:background="#5dff22"

        android:id ="@+id/zoomControlId"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"></ZoomControls>


</LinearLayout>