android 双击图片放大,再双击缩小效果 【安卓进化九】
今天写了个onDoubleTap事件的处理方法,双击屏幕事件的放大缩小的程序,双击屏幕图片放大,再双击屏幕图片缩小到原来的效果。 请看截图的效果!
原图: 双击屏幕放大后的效果:
现把代码贴出来:
一、MainActivty.java类中的代码:
package com.cn.android;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.GestureDetector;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.GestureDetector.OnGestureListener;
public class mainActivity extends Activity implements OnGestureListener{
private ImageShowView mImageShowView = null;
private GestureDetector gestureScanner;
private double Scale = 1.0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mImageShowView = new ImageShowView(this);
setContentView(mImageShowView);
gestureScanner = new GestureDetector(this);
gestureScanner.setOnDoubleTapListener(new GestureDetector.OnDoubleTapListener(){
@Override
public boolean onDoubleTap(MotionEvent e) {
// TODO Auto-generated method stub
// 双击时产生一次
if(Scale == 1.0){
Scale = Scale + 0.5;
mImageShowView.setScale(Scale);
}
else if(Scale == 1.5){
Scale = Scale - 0.5;
mImageShowView.setScale(Scale);
}
Log.v("daming", "onDoubleTap");
return true;
}
@Override
public boolean onDoubleTapEvent(MotionEvent e) {
// TODO Auto-generated method stub
// 双击时产生两次
Log.v("daming", "onDoubleTapEvent");
return false;
}
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
//短快的点击算一次单击
Log.v("daming", "onSingleTapConfirmed");
return false;
}
});
}
@Override
public boolean onTouchEvent(MotionEvent me) {
return gestureScanner.onTouchEvent(me);
}
@Override
public boolean onDown(MotionEvent e) {
补充:移动开发 , Android ,