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>
thistimebd Bangladesh Live online newsportal, education, Lifestyle, Health, Photography, gif image etc.
Make your own name or company name website | contact: thistimebd24@gmail.com
Copyright © 2020-2024 News Portal in Bangladesh - THISTIMEBD.COM. ALL Rights Reserved.