用zoom放大缩小缩缩片缩import android.app.Activity;import android.os.Bundle;public class zooming extends Activity{
/**Called when the activity is first created.*/
@Overridepublic void onCreate(Bundle icicle) {super.onCreate(icicle);setContentView(new Zoom(this));
}
}
<pre name="code"class="java">import android.content.Context;import android.graphics.Canvas;import android.graphics.drawable.Drawable;import android.view.KeyEvent;import android.view.View;public class Zoom extends View{private Drawable image;private int zoomControler=20;public Zoom(Context context)
{super(context);image=context.getResources().getDrawable(R.drawable.icon);setFocusable(true);
}
@Overrideprotected void onDraw(Canvas canvas) {
//TODO Auto-generated method stubsuper.onDraw(canvas);
//here u can control the width and height of the images. . . . . . . . this line is very importantimage.setBounds((getWidth()/2)-zoomControler, (getHeight()/2)-zoomControler, (getWidth()/2)+zoomControler, (getHeight()/2)+zoomControler);image.draw(canvas);
}
@Overridepublic boolean onKeyDown(int keyCode,KeyEvent event) {if(keyCode==KeyEvent.KEYCODE_DPAD_UP)//zoom inzoomControler+=10;if(keyCode==KeyEvent.KEYCODE_DPAD_DOWN) //zoom outzoomControler-=10;if(zoomControler<10)zoomControler=10;invalidate();return true;
}
}package com.min.Test_Gallery;
import android.app.Activity;import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.graphics.Color;import android.graphics.Matrix;import android.os.Bundle;import android.util.DisplayMetrics;import android.util.Log;import android.view.GestureDetector;import android.view.KeyEvent;import android.view.MotionEvent;import android.view.View;import android.view.GestureDetector.OnGestureListener;import android.view.View.OnTouchListener;import android.widget.Button;import android.widget.FrameLayout;import android.widget.ImageView;import android.widget.LinearLayout;import android.widget.Toast;public class DisplayImage extends Activity implementsOnTouchListener, OnGestureListener {private static final String TAG = "DisplayImage";private static final int FLING_MIN_DISTANCE = 100;private static final int FLING_MIN_VELOCITY = 200;
/*相量声明*/private ImageView mImageView;private Button mButton01;private Button mButton02;private FrameLayout layout1;private LinearLayout layoutImage;private Bitmap bmp;private int id=0;private int displayWidth;private int displayHeight;private float scaleWidth=1;private float scaleHeight=1;private GestureDetector mGestureDetector;
/** Called when the activity is first created. */
@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState) ;
/*加display.xml Layout */setContentView(R.layout.display) ;
/*取得屏幕分辨率大小*/
DisplayMetrics dm=new DisplayMetrics( ) ;getWindowManager( ) .getDefaultDisplay( ) .getMetrics(dm) ;displayWidth=dm.widthPixels;displayHeight=dm.heightPixels;
/*初始化相量*/
Bundle bundle = this.getIntent( ) .getExtras( ) ;
Integer imageId = bundle.getInt("imageId") ;
Log.i(TAG, "onCreate, imageId = " + imageId) ;bmp=BitmapFactory.decodeResource(getResources( ) ,imageId) ;mImageView = (ImageView)findViewById(R.id.myImageView) ;mImageView.setImageBitmap(bmp) ;mImageView.setOnTouchListener(this) ;mImageView.setLongClickable(true) ;layout1 = (FrameLayout)findViewById(R.id.layout1) ;layoutImage =(LinearLayout)findViewById(R.id.layoutImage) ;mButton01 = (Button)findViewById(R.id.myButton1) ;mButton02 = (Button)findViewById(R.id.myButton2) ;
/* 小按onClickListener */mButton01.setOnClickListener(new
Button.OnClickListener( ) {
@Overridepublic void onClick(View v) {small( ) ;
}
} ) ;
/*放大按onClickListener */mButton02.setOnClickListener(new
Button.OnClickListener( ) {
@Overridepublic void onClick(View v) {big( ) ;
}
} ) ;
}
//用触触摸屏由1个MotionEvent ACTION_DOWN触
@Overridepublic boolean onDown(MotionEvent e) {
// TODO Auto-generated method stub
// Toast.makeText(this, "onDown",Toa s t.LENGTH_SHOR T) .sh o w() ;
Log.i(TAG, "onDown. . . ") ;return false;
}
/*用按下触摸屏、快速移后松由1个MotionEvent ACTION_DOWN,
*多个ACTION_MOVE, 1个ACTION_UP触
*参数解
* e1 第1个ACTION_DOWN MotionEvent
* e2最后一个ACTION_MOVE MotionEvent
* vel oci tyXX上的移速度像素/秒
* velocityYY上的移速度像素/秒
*触条件
* X 的坐 位移大于FL ING_MIN_DIS TANCE 且移 速度大于FLING_MIN_VELOCITY个像素/秒
* @seeandroid.view.GestureDetector$OnGestureListener#onFling(android.view.MotionEvent, android.view.MotionEvent, float, float)
*/
@Overridepublic boolean onFling(MotionEvent e1, MotionEvent e2, floatvelocityX,float velocityY) {
// TODO Auto-generated method stub
Log.i(TAG, "onFling. . . ") ;if (e1.getX( ) - e2.getX( ) > FLING_MIN_DISTANCE
&& Math.abs(velocityX) > FLING_MIN_VELOCITY) {
// Fling left
Toast.makeText(this, "Fling Left",Toast.LENGTH_SHORT) .show( ) ;
} else if (e2.getX( ) - e1.getX( ) > FLING_MIN_DISTANCE
&& Math.abs(velocityX) > FLING_MIN_VELOCITY) {
// Fling right
Toast.makeText(this, "Fling Right",Toast.LENGTH_SHORT) .show( ) ;
}return false;
}
//用按触摸屏由多个MotionEvent ACTION_DOWN触
@Overridepublic void onLongPress(MotionEvent e) {
// TODO Auto-generated method stub
Log.i(TAG, "onLongPress. . . ") ;
}
//用按下触摸屏 并拖 由1个MotionEvent ACTION_DOWN, 多个ACTION_MOVE触
@Overridepublic boolean onScroll(MotionEvent e1, MotionEvent e2,float distanceX,float distanceY) {
// TODO Auto-generated method stub
Log.i(TAG, "onScroll. . . ") ;return false;
}
//用触触摸屏尚未松或拖由一个1个MotionEvent ACTION_DOWN触
//注意和onDown()的区强的是没有松或者拖的状
@Overridepublic void onShowPress(MotionEvent e) {
// TODO Auto-generated method stub
Log.i(TAG, "onShowPress. . . ") ;
}
//用 触触摸屏后松由一个1个MotionEvent ACTION_UP触@Overridepublic boolean onSingleTapUp(MotionEvent e) {
// TODO Auto-generated method stub
Log.i(TAG, "onSingleTapUp. . . ") ;return false;
}
@Overridepublic boolean onTouch(View v, MotionEvent event) {// TODO Auto-generated method stub
Log.i(TAG, "onTouch. . . ") ;
// Set button visiblemButton01.setVisibility(View.VISIBLE) ;mButton02.setVisibility(View.VISIBLE) ;return mGestureDetector.onTouchEvent(event) ;}
// @Override
// public boolean onTouchEvent(MotionEvent event) {// // TODO Auto-generated method stub
// super.onTouchEvent(event) ;
//
// Log.i (TAG, "onTouchEvent") ;
// // Set button visible
// mButton01.setVisibility(View.VISIBLE) ;
// mButton02.setVisibility(View.VISIBLE) ;
//
// return true;
// }
@Overridepublic boolean onKeyDown(int keyCode, KeyEvent event) {// TODO Auto-generated method stubsuper.onKeyDown(keyCode, event) ;
Log.i(TAG, "onKeyDown. . . ") ;
// Set button visiblemButton01.setVisibility(View.VISIBLE) ;mButton02.setVisibility(View.VISIBLE) ;return true;
}
/* 片小的method */private void small( ) {int bmpWidth=bmp.getWidth( ) ;int bmpHeight=bmp.getHeight( ) ;
Log.i(TAG, "bmpWidth = " + bmpWidth + ", bmpHeight = "+ bmpHeight) ;
/* 置片小的比例*/double scale=0.8;
/* 算出次要小的比例*/scaleWidth=(float) (scaleWidth*scale) ;scaleHeight=(float) (scaleHeight*scale) ;
/* 生reSize后的Bitmap象*/
Matrix matrix = new Matrix( ) ;matrix.postScale(scaleWidth, scaleHeight) ;
Bitmap resizeBmp =Bitmap.createBitmap(bmp,0,0,bmpWidth,bmpHeight,matrix,true) ;if(id==0) {
/*如果是第一次按就除原来默的ImageVi ew */layoutImage.removeView(mImageView) ;
} else {
/*如果不是第一次按就除上次放大小所生的ImageVi ew */layoutImage.removeView( (ImageView)findViewById(id) ) ;
}
/* 生新的ImageView放入reSize的Bitmap 象再放入Layout中*/id++;
ImageView imageView = new ImageView(this) ;imageView.setId(id) ;imageView.setImageBitmap(resizeBmp) ;layoutImage.addView(imageView) ;
Log.i(TAG, "imageView.getWidth( ) = " +imageView.getWidth( )
+ ", imageView.getHeight( ) = " +imageView.getHeight( ) ) ;setContentView(layout1) ;
/*因 片放到最大放大按会disable所以在小把它重 enable
*/mButton02.setEnabled(true) ;mButton02.setTextColor(Color.MAGENTA) ;
}
/* 片放大的method */private void big( ) {int bmpWidth=bmp.getWidth( ) ;int bmpHeight=bmp.getHeight( ) ;
Log.i(TAG, "bmpWidth = " + bmpWidth + ", bmpHeight = "+ bmpHeight) ;
/* 置片放大的比例*/double scale=1.25;
/* 算次要放大的比例*/scaleWidth=(float) (scaleWidth*scale) ;
scaleHeight=(float) (scaleHeight*scale) ;
/* 生reSize后的Bitmap象*/
Matrix matrix = new Matrix( ) ;matrix.postScale(scaleWidth, scaleHeight) ;
Bitmap resizeBmp =Bitmap.createBitmap(bmp,0,0,bmpWidth,bmpHeight,matrix,true) ;if(id==0) {
/*如果是第一次按就除原来置的ImageVi ew */layoutImage.removeView(mImageView) ;
} else {
/*如果不是第一次按就除上次放大小所生的ImageVi ew */layoutImage.removeView( (ImageView)findViewById(id) ) ;
}
/* 生新的ImageView放入reSize的Bitmap 象再放入Layout中*/id++;
ImageView imageView = new ImageView(this) ;imageView.setId(id) ;imageView.setImageBitmap(resizeBmp) ;layoutImage.addView(imageView) ;setContentView(layout1) ;
/*如果再放大会超屏幕大小就把Button disable */if( scaleWidth * scale * bmpWidth > bmpWidth * 3 | |scaleHeight * scale * bmpHeight > bmpWidth * 3 | |scaleWidth * scale * bmpWidth > displayWidth * 5| |scaleHeight * scale * bmpHeight > displayHeight *
5) {mButton02.setEnabled(false) ;mButton02.setTextColor(Color.GRAY) ;
} else {mButton02.setEnabled(true) ;mButton02.setTextColor(Color.MAGENTA) ;}
}
}display.xml文件
<?xml version="1.0" encoding="utf-8"?>
<FrameLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"android:id="@+id/layout1"
>
<ScrollViewxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="wrap_content"
3adapted some code to create a TouchImageView that supports multitouch(>21) It is inspiredby the book Hel lo,Android! (3rd edition)
It is contained within the fol lowing 3 fi les TouchImageViewjava WrapMotionEventjava
WrapMotionEvent java
TouchImageView.javaimport se.robertfoss.ChanImageBrowser.Viewer;import android.content.Context;import android.graphics.Bitmap;import android.graphics.Matrix;import android.graphics.PointF;import android.util.FloatMath;import android.util.Log;import android.view.MotionEvent;import android.view.View;import android.widget.ImageView;public class TouchImageView extends ImageView{private static final String TAG="Touch";
//These matrices will be used to move and zoom image
Matrix matrix=new Matrix();
Matrix savedMatrix=new Matrix();
//We can be in one of these 3 statesstatic final int NONE=0;static final int DRAG=1;static final int ZOOM=2;int mode=NONE;
//Remember some things for zooming
PointF start=new PointF();
PointF mid=new PointF();float oldDist=1f;
Context context;
2022年春节假期陆续结束,根据惯例在春节之后各大云服务商会继续开始一年的促销活动。今年二月中旬会开启新春采购季的活动,我们已经看到腾讯云商家在春节期间已经有预告活动。当时已经看到有抢先优惠促销活动,目前我们企业和个人可以领取腾讯云代金券满减活动,以及企业用户可以领取域名优惠低至.COM域名1元。 直达链接 - 腾讯云新春采购活动抢先看活动时间:2022年1月20日至2022年2月15日我们可以在...
spinservers是Majestic Hosting Solutions LLC旗下站点,主要提供国外服务器租用和Hybrid Dedicated等产品的商家,数据中心包括美国达拉斯和圣何塞机房,机器一般10Gbps端口带宽,高配置硬件,支持使用PayPal、信用卡、支付宝或者微信等付款方式。目前,商家针对部分服务器提供优惠码,优惠后达拉斯机房服务器最低每月89美元起,圣何塞机房服务器最低每月...
哪里购买香港云服务器便宜?众所周知,国内购买云服务器大多数用户会选择阿里云或腾讯云,但是阿里云香港云服务器不仅平时没有优惠,就连双十一、618、开年采购节这些活动也很少给出优惠。那么,腾讯云虽然海外云有优惠活动,但仅限新用户,购买过腾讯云服务器的用户就不会有优惠了。那么,我们如果想买香港云服务器,怎么样购买香港云服务器便宜和优惠呢?下面,云服务器网(yuntue.com)小编就介绍一下!我们都知道...