I have a question around image scale when dragging an ImageView around a device.
The image I have is 5257 pixels x 3423 pixels so its fairly large. I have coded the mechasim for dragging the image and this works fine (See the code below).
However my problem comes when I run the project and the device shows the image as a zoomed out version of the image. I want the image to be at "100%" view depth. ie 5257 pixels x 3423 pixels
When I alter scaleType from matrix to FixXY it fixes the scale however it no longer allows me to drag the image around. I assume this is due to the FixXY expanding the content to the FrameLayout and prevents it from being moved.
So my question is. Can I use the matrix ScaleType while having a FixXY zoom depth?
I have been looking around this for a while. However most other articles are around keeping the image in the view window setting the iamge to 100% of the view window, which is not what I want.
So hopefully someone can help?
My Layout file is:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="21028dp"
android:layout_height="13696dp"
android:scaleType="matrix">
<ImageView android:id="@+id/imageView"
android:layout_width="5257dp"
android:layout_height="3424dp"
android:src="@mipmap/plan"
android:adjustViewBounds="false"
android:scaleType="matrix">
</ImageView>
</FrameLayout>
My code is for this project is:
import android.app.Activity;
import android.graphics.Matrix;
import android.graphics.PointF;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.ImageView;
public class SubScreen6 extends Activity implements OnTouchListener {
private static final String TAG = "Touch";
// These matrices will be used to move and zoom image
Matrix matrix = new Matrix();
Matrix savedMatrix = new Matrix();
// We can be in one of these 3 states
static final int NONE = 0;
static final int DRAG = 1;
static final int ZOOM = 2;
int mode = NONE;
// Remember some things for zooming
PointF start = new PointF();
PointF mid = new PointF();
float oldDist = 1f;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sub_screen6);
ImageView view = (ImageView) findViewById(R.id.imageView);
try{
view.setOnTouchListener(SubScreen6.this);
}catch(Exception ex)
{
ex.printStackTrace();
}
}
@Override
public boolean onTouch(View v, MotionEvent event) {
ImageView view = (ImageView) v;
int rotation = 25;
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
savedMatrix.set(matrix);
start.set(event.getX(), event.getY());
mode = DRAG;
break;
case MotionEvent.ACTION_MOVE:
if (mode == DRAG) {
matrix.set(savedMatrix);
matrix.postTranslate(event.getX() - start.x,
event.getY() - start.y);
}
break;
}
view.setImageMatrix(matrix);
return true;
}