嗨,我已經下載樣本庫資源。如果我運行它的指示MyGestureDectector不能解析爲類型錯誤....如何解決這些錯誤?請幫我.....錯誤:MyGestureDetector無法解析爲類型。怎麼解決?
編碼:
package Gallery.Gallery;
import android.app.Activity;
import android.content.Context;
import android.graphics.Matrix;
import android.graphics.PointF;
import android.os.Bundle;
import android.util.FloatMath;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
public class Gallery extends Activity {
public ImageView img1,img2,img3;
public static ImageView contentImage;
boolean click1=true;
boolean click2=true;
boolean click3=true;
boolean imageTouch=false;
Context myContext=Gallery.this;
Matrix matrix = new Matrix();
Matrix savedMatrix = new Matrix();
PointF start=new PointF();
PointF mid = new PointF();
float oldDist = 1f;
static final int NONE = 0;
static final int DRAG = 1;
static final int ZOOM = 2;
int mode = NONE;
public GestureDetector mDetector;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mDetector = new GestureDetector(Gallery.this,new MyGestureDetector(Gallery.this));
Button btn1=(Button)findViewById(R.id.button1);
Button btn2=(Button)findViewById(R.id.button2);
Button btn3=(Button)findViewById(R.id.button3);
img1=(ImageView)findViewById(R.id.imageView1);
img2=(ImageView)findViewById(R.id.imageView2);
img3=(ImageView)findViewById(R.id.imageView3);
contentImage=(ImageView)findViewById(R.id.contentImage);
img1.setAlpha(100);
img2.setAlpha(100);
img3.setAlpha(100);
btn1.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View arg0)
{
if (click1)
{
img1.setAlpha(255);
img2.setAlpha(100);
img3.setAlpha(100);
click1=false;
}
else
{
img1.setAlpha(255);
img2.setAlpha(100);
img3.setAlpha(100);
click1=true;
}
}
});
btn2.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View arg0)
{
if (click2)
{
img1.setAlpha(100);
img2.setAlpha(255);
img3.setAlpha(100);
click2=false;
}
else
{
img1.setAlpha(80);
img2.setAlpha(255);
img3.setAlpha(80);
click2=true;
}
}
});
btn3.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View arg0)
{
if (click3)
{
img1.setAlpha(100);
img2.setAlpha(100);
img3.setAlpha(255);
click3=false;
}
else
{
img1.setAlpha(100);
img2.setAlpha(100);
img3.setAlpha(255);
click3=true;
}
}
});
img1.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
if (click1)
{
img1.setAlpha(255);
img2.setAlpha(100);
img3.setAlpha(100);
click1=false;
}
else
{
img1.setAlpha(255);
img2.setAlpha(100);
img3.setAlpha(100);
click2=true;
}
contentImage.setImageResource(R.drawable.img1);
}
});
img2.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
if (click2)
{
img1.setAlpha(100);
img2.setAlpha(255);
img3.setAlpha(100);
click2=false;
}
else
{
img1.setAlpha(80);
img2.setAlpha(255);
img3.setAlpha(80);
click2=true;
}
contentImage.setImageResource(R.drawable.img2);
}
});
img3.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
if (click3)
{
img1.setAlpha(100);
img2.setAlpha(100);
img3.setAlpha(255);
click3=false;
}
else
{
img1.setAlpha(100);
img2.setAlpha(100);
img3.setAlpha(255);
click3=true;
}
contentImage.setImageResource(R.drawable.img3);
}
});
contentImage.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);
start.set(event.getX(), event.getY());
mode = DRAG;
break;
case MotionEvent.ACTION_POINTER_DOWN:
oldDist = spacing(event);
if (oldDist > 10f)
{
savedMatrix.set(matrix);
midPoint(mid, 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() - start.x,
event.getY() - start.y);
}
else if (mode == ZOOM)
{
float newDist = spacing(event);
if (newDist > 10f)
{
matrix.set(savedMatrix);
float scale = newDist/oldDist;
matrix.postScale(scale, scale, mid.x, mid.y);
}
}
break;
}
view.setImageMatrix(matrix);
return true;
}
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);
}
});
}//onCreate Method over.....
}
錯誤行:
mDetector = new GestureDetector(Gallery.this,new MyGestureDetector(Gallery.this));
MyGestureDetector不能被解析爲一個類型Gallery.java /畫廊/ src目錄/相冊/畫廊線41 Java問題