public class ImageActivity extends Activity implements GestureDetector.OnGestureListener{
private ImageView mImage;
private ImageLoader mImageLoader;
private boolean change;
private GestureDetector detector;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_image);
mImage = (ImageView) findViewById(R.id.imageview);
Bitmap bmp = null;
// try {
// bmp = MediaStore.Images.Media.getBitmap(this.getContentResolver(), Uri.parse("http://img.mp.itc.cn/upload/20160816/e24c8031a95649778ecaa111b3f5cf76_th.jpg"));
// } catch (IOException e) {
// e.printStackTrace();
// }
// mImage.setImageBitmap(bmp);
// mImage.setImageURI(Uri.parse("http://img.mp.itc.cn/upload/20160816/e24c8031a95649778ecaa111b3f5cf76_th.jpg"));
RequestQueue queue = Volley.newRequestQueue(ImageActivity.this);
// ImageRequest request = new ImageRequest("http://img.mp.itc.cn/upload/20160816/e24c8031a95649778ecaa111b3f5cf76_th.jpg", new Response.Listener<Bitmap>() {
// @Override
// public void onResponse(Bitmap response) {
// mImage.setImageBitmap(response);
// }
// },200,200, Bitmap.Config.ARGB_8888, new Response.ErrorListener() {
// @Override
// public void onErrorResponse(VolleyError error) {
//
// }
// });
//图片的长按事件
mImageLoader = new ImageLoader(queue, new ImageLoader.ImageCache() {
@Override
public Bitmap getBitmap(String url) {
return null;
}
@Override
public void putBitmap(String url, Bitmap bitmap) {
}
});
ImageLoader.ImageListener listener = ImageLoader.getImageListener(mImage, R.mipmap.ic_launcher, R.mipmap.ic_launcher);
mImageLoader.get("http://img.mp.itc.cn/upload/20160816/e24c8031a95649778ecaa111b3f5cf76_th.jpg", listener);
// queue.add(request);
mImage.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
if (change) {
Toast.makeText(ImageActivity.this, "长按事件", Toast.LENGTH_LONG).show();
}
return false;
}
});
mImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mImage.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
change = true;
}
});
mImage.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
/**
* 将手势的点击事件和图片联系到一起
*
*/
MotionEvent obtain = MotionEvent.obtain(event);
obtain.setLocation(event.getRawX(),event.getRawX());
return detector.onTouchEvent(obtain);
// return false;
}
});
detector = new GestureDetector(ImageActivity.this,this);
detector.setOnDoubleTapListener(new GestureDetector.OnDoubleTapListener() {
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
Toast.makeText(ImageActivity.this, "单击事件", Toast.LENGTH_LONG).show();
return false;
}
//双击事件调一次次
@Override
public boolean onDoubleTap(MotionEvent e) {
Toast.makeText(ImageActivity.this, "双击事件", Toast.LENGTH_LONG).show();
return false;
}
//双击事件调两次
@Override
public boolean onDoubleTapEvent(MotionEvent e) {
// Toast.makeText(ImageActivity.this, "双击事件", Toast.LENGTH_LONG).show();
return false;
}
});
}
@Override
public boolean onDown(MotionEvent e) {
return true;
}
@Override
public void onShowPress(MotionEvent e) {
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
return false;
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
return false;
}
@Override
public void onLongPress(MotionEvent e) {
Toast.makeText(ImageActivity.this, "长按事件", Toast.LENGTH_LONG).show();
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
return false;
}
}
View单击双击长按事件
最新推荐文章于 2023-12-21 10:59:02 发布