package com.szxys.doubleclike;import android.app.Activity;import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.graphics.Matrix;import android.graphics.drawable.BitmapDrawable;import android.graphics.drawable.Drawable;import android.os.Bundle;import android.provider.ContactsContract.CommonDataKinds.Im;import android.view.View;import android.view.animation.Animation;import android.view.animation.ScaleAnimation;import android.widget.ImageView;public class DoubleClickActivity extends Activity {/** Called when the activity is first created. */private ImageView image;private Bitmap bitmap;private boolean isbig = false;private int count = 2;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);image = (ImageView) findViewById(R.id.image);bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.girl_1);image.setBackgroundResource(R.drawable.girl_1);image.setOnClickListener(new clike());}private long sTime = 0;private long eTime = 0;private Drawable drawable;interface TimeListener{public long getCurrentTime();}class clike implements View.OnClickListener,  TimeListener{@Overridepublic long getCurrentTime() {// TODO Auto-generated method stubreturn System.currentTimeMillis();}@Overridepublic void onClick(View v) {// TODO Auto-generated method stubif(sTime!=0&&(getCurrentTime()-sTime>500)){sTime = 0;count=2;}if (!isbig) {--count;if (count > 0) {sTime = getCurrentTime();System.out.println(sTime + "--s--");}if (count == 0) {eTime = getCurrentTime();System.out.println(sTime + "--e--");if ((eTime - sTime) <= 500) {drawable = resizeImage(bitmap,bitmap.getWidth() * 4, bitmap.getHeight() * 4);image.setBackgroundDrawable(drawable);ScaleAnimation animation = new ScaleAnimation(0.25f, 1.0f, 0.25f, 1.0f,Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0f);animation.setDuration(500);animation.setAnimationListener(new Animation.AnimationListener() {@Overridepublic void onAnimationStart(Animation animation) {// TODO Auto-generated method stub}@Overridepublic void onAnimationRepeat(Animation animation) {// TODO Auto-generated method stub}@Overridepublic void onAnimationEnd(Animation animation) {// TODO Auto-generated method stubisbig = true;sTime = 0;eTime = 0;count = 2;}});image.setAnimation(animation);System.out.println("----------haha--------------");}}}else{--count;if (count > 0) {sTime = getCurrentTime();System.out.println(sTime + "--s--");}if (count == 0) {eTime = getCurrentTime();System.out.println(sTime + "--e--");Drawable Tempdrawable = drawable;final Bitmap bitmap = ((BitmapDrawable)Tempdrawable).getBitmap();if ((eTime - sTime) <= 500) {drawable = resizeImage(bitmap,bitmap.getWidth()/4, bitmap.getHeight()/4);ScaleAnimation animation = new ScaleAnimation(1.0f, 0.25f, 1.0f, 0.25f,Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0f);animation.setDuration(500);animation.setAnimationListener(new Animation.AnimationListener() {@Overridepublic void onAnimationStart(Animation animation) {}@Overridepublic void onAnimationRepeat(Animation animation) {}@Overridepublic void onAnimationEnd(Animation animation) {image.clearAnimation();image.setBackgroundDrawable(drawable);isbig = false;sTime = 0;eTime = 0;count = 2;}});image.setBackgroundDrawable(Tempdrawable);image.setAnimation(animation);System.out.println("----------haha--------------");}}}}}// 压缩图片到指定大小public static Drawable resizeImage(Bitmap bitmap, int w, int h) {Bitmap BitmapOrg = bitmap;int width = BitmapOrg.getWidth();int height = BitmapOrg.getHeight();int newWidth = w;int newHeight = h;float scaleWidth = ((float) newWidth) / width;float scaleHeight = ((float) newHeight) / height;Matrix matrix = new Matrix();matrix.postScale(scaleWidth, scaleHeight);Bitmap resizedBitmap = Bitmap.createBitmap(BitmapOrg, 0, 0, width,height, matrix, true);return new BitmapDrawable(resizedBitmap);}}

更多相关文章

  1. android加载本地图片
  2. Android 从网络加载图片
  3. Android从相机或相册获取图片裁剪
  4. android camera2 api点击图片实现聚焦
  5. android 读取sd卡中的图片
  6. Android drawableleft如何设置图片大小
  7. android自带图片资源图标一览,android.R.drawable
  8. ImageView设置图片大小
  9. Android简单图片浏览器

随机推荐

  1. 为获得快速结果,我的查询有什么好的索引?
  2. 读《SQL优化核心思想》:你不知道的优化技
  3. Android如何通过JDBC直连访问MySQL数据库
  4. MySQL各模块工作配合
  5. mysql主从同步(4)-Slave延迟状态监控
  6. Windows下DOS命令大全
  7. Mysql Where使用列别名
  8. mysql存储过程的使用
  9. mysql组并对UNION进行排序
  10. 通过 MySQL 存储原理来分析排序和锁(转)