Implement pinch-to-zoom with ScaleGestureDetector

Implement pinch-to-zoom with ScaleGestureDetector - Hello Friend GENERAL INFO FOR ANDROID DEVELOPMENT, In the article you read this time with the title Implement pinch-to-zoom with ScaleGestureDetector, We have prepared this article for you to read and retrieve information there in. Hopefully the contents of postings Artikel Android code sample: Detecting Gestures, We write this you can understand. Alright, good read.

The Title : Implement pinch-to-zoom with ScaleGestureDetector
link : Implement pinch-to-zoom with ScaleGestureDetector

Read also


Implement pinch-to-zoom with ScaleGestureDetector


Last post show how to implement ScaleGestureDetector, this post show how to implement pinch-to-zoom on ImageView with ScaleGestureDetector.


MainActivity.java
package com.blogspot.android_er.androidscalegesturedetector;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.widget.ImageView;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

TextView textMsg;
ImageView myImage;

private ScaleGestureDetector scaleGestureDetector;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textMsg = (TextView)findViewById(R.id.msg);
myImage = (ImageView)findViewById(R.id.myimage);

scaleGestureDetector = new ScaleGestureDetector(
this, new MySimpleOnScaleGestureListener(textMsg, myImage));
}

@Override
public boolean onTouchEvent(MotionEvent event) {
scaleGestureDetector.onTouchEvent(event);
return true;
//return super.onTouchEvent(event);
}

private class MySimpleOnScaleGestureListener
extends ScaleGestureDetector.SimpleOnScaleGestureListener{

TextView viewMessage;
ImageView viewMyImage;

float factor;

public MySimpleOnScaleGestureListener(TextView v, ImageView iv) {
super();
viewMessage = v;
viewMyImage = iv;
}

@Override
public boolean onScaleBegin(ScaleGestureDetector detector) {
factor = 1.0f;
return true;
//return super.onScaleBegin(detector);
}

@Override
public boolean onScale(ScaleGestureDetector detector) {

float scaleFactor = detector.getScaleFactor() - 1;
factor += scaleFactor;
viewMessage.setText(String.valueOf(scaleFactor)
+ "\n" + String.valueOf(factor));
viewMyImage.setScaleX(factor);
viewMyImage.setScaleY(factor);
return true;
//return super.onScale(detector);
}
}
}


activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:padding="16dp"
android:orientation="vertical"
tools:context="com.blogspot.android_er.androidscalegesturedetector.MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:autoLink="web"
android:text="http://android-er.blogspot.com/"
android:textStyle="bold" />
<TextView
android:id="@+id/msg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="24sp"/>
<ImageView
android:id="@+id/myimage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher"/>
</LinearLayout>


Next:
Implement ScaleGestureDetector on individual ImageView



Thus Article Implement pinch-to-zoom with ScaleGestureDetector

The End Article Implement pinch-to-zoom with ScaleGestureDetector This time, hopefully can give benefits to all of you. well, see you in posting other articles.

You are now reading the article Implement pinch-to-zoom with ScaleGestureDetector with the link address http://xorislogo.blogspot.com/2016/05/implement-pinch-to-zoom-with.html

0 Response to "Implement pinch-to-zoom with ScaleGestureDetector"

Post a Comment