-1
我有一個ImageView縮放應用程序在我的手機上運行,當我第一次運行它時,圖像工作和縮放以及後,我做了一個鏈接按鈕到圖像視圖,與以前的應用程序相同,圖像出現但沒有縮放,並且根本不移動ImageView縮放不放大或縮小
有人可以幫忙嗎?
mapslocations.xml
<Button
android:id="@+id/powerstationread"
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.powerstationread);
/**
* 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/powerstationread"
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);
}
}
我不明白:)你的意思是把Sites.java放在PagePowerstation.java中? – Sarah 2014-08-27 17:27:45
除了'setContentView(R.layout.imageview1);你不覺得你需要代碼才能真正做東西嗎?你不是在PagePowerstation.java中沒有任何東西? – r2DoesInc 2014-08-27 17:29:05
我迷路了:) ...您是否在PagePowerstation.java中輸入了更多的代碼以用於setContentView(R.layout.imageview1);? – Sarah 2014-08-27 17:37:57