Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » ImageView zooming is not zooming in or out(eclipse android java xml)
ImageView zooming is not zooming in or out [message #1414179] Sat, 30 August 2014 14:12 Go to next message
Freed Shom is currently offline Freed ShomFriend
Messages: 2
Registered: July 2014
Junior Member
I have an ImageView zoom application ran on my mobile, when I first run it, the image work and the zooming as well, after that, I made a link button to the image view, with the same previous application, the image appears but no zooming for it and it doesn't move at all

Can someone help?

mapslocations.xml

<Button
                android:id="@+id/pslook1"
                android:layout_width="fill_parent"
                android:layout_height="45dp"
                android:layout_alignParentRight="true"
                android:layout_alignParentTop="true"
                android:layout_weight="1"
                android:gravity="center"
                android:text="Map"
                android:textSize="10sp"
                android:textStyle="italic" />


Sites.java

package com.f.fa;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.Matrix;
import android.graphics.PointF;
import android.os.Bundle;
import android.util.FloatMath;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;

public class Sites extends Activity {
 ImageView imageDetail1;
 Matrix matrix = new Matrix();
 Matrix savedMatrix = new Matrix();
 PointF startPoint = new PointF();
 PointF midPoint = new PointF();
 float oldDist = 1f;
 static final int NONE = 0;
 static final int DRAG = 1;
 static final int ZOOM = 2;
 int mode = NONE;

 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.mapslocations);
  imageDetail1 = (ImageView) findViewById(R.id.pslook1);
  /**
   * set on touch listner on image
   */
  imageDetail1.setOnTouchListener(new View.OnTouchListener() {

   @Override
   public boolean onTouch(View v, MotionEvent event) {

    ImageView view = (ImageView) v;
    System.out.println("matrix=" + savedMatrix.toString());
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:

     savedMatrix.set(matrix);
     startPoint.set(event.getX(), event.getY());
     mode = DRAG;
     break;

    case MotionEvent.ACTION_POINTER_DOWN:

     oldDist = spacing(event);

     if (oldDist > 10f) {
      savedMatrix.set(matrix);
      midPoint(midPoint, event);
      mode = ZOOM;
     }
     break;

    case MotionEvent.ACTION_UP:

    case MotionEvent.ACTION_POINTER_UP:
     mode = NONE;

     break;

    case MotionEvent.ACTION_MOVE:
     if (mode == DRAG) {
      matrix.set(savedMatrix);
      matrix.postTranslate(event.getX() - startPoint.x,
        event.getY() - startPoint.y);
     } else if (mode == ZOOM) {
      float newDist = spacing(event);
      if (newDist > 10f) {
       matrix.set(savedMatrix);
       float scale = newDist / oldDist;
       matrix.postScale(scale, scale, midPoint.x, midPoint.y);
      }
     }
     break;

    }
    view.setImageMatrix(matrix);

    return true;
   }

   @SuppressLint("FloatMath")
   private float spacing(MotionEvent event) {
    float x = event.getX(0) - event.getX(1);
    float y = event.getY(0) - event.getY(1);
    return FloatMath.sqrt(x * x + y * y);
   }
   private void midPoint(PointF point, MotionEvent event) {
    float x = event.getX(0) + event.getX(1);
    float y = event.getY(0) + event.getY(1);
    point.set(x / 2, y / 2);
   }
  });
 }
}


imageview1.xml

<ImageView
    android:id="@+id/pslook1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:scaleType="matrix"
    android:src="@drawable/powerstationwallmap" />


PagePowerstation.java

package com.f.fa;

import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;

public class PagePowerstation extends Activity {

    Button imageview1;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.imageview1);
    }
}
Re: ImageView zooming is not zooming in or out [message #1414357 is a reply to message #1414179] Sun, 31 August 2014 03:28 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin DahyabhaiFriend
Messages: 3511
Registered: July 2009
Senior Member

This isn't the forum for questions about developing Android apps, it's for using Eclipse. See https://www.eclipse.org/forums/index.php/t/225513/ .

Nitin Dahyabhai
Eclipse Web Tools Platform
Re: ImageView zooming is not zooming in or out [message #1414477 is a reply to message #1414357] Sun, 31 August 2014 12:15 Go to previous message
Freed Shom is currently offline Freed ShomFriend
Messages: 2
Registered: July 2014
Junior Member
Thank you
Previous Topic:Eclipse Keys assignment: how to add When: Debug View?
Next Topic:breakpoints
Goto Forum:
  


Current Time: Sat Oct 19 18:16:35 GMT 2019

Powered by FUDForum. Page generated in 0.02696 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top