Android用zoom放大缩小图片参考模板Word格式文档下载.docx
- 文档编号:14036527
- 上传时间:2022-10-17
- 格式:DOCX
- 页数:23
- 大小:22.97KB
Android用zoom放大缩小图片参考模板Word格式文档下载.docx
《Android用zoom放大缩小图片参考模板Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《Android用zoom放大缩小图片参考模板Word格式文档下载.docx(23页珍藏版)》请在冰豆网上搜索。
created.
*/
@Override
void
onCreate(Bundle
icicle)
super.onCreate(icicle);
setContentView(new
Zoom(this));
}
<
pre
name="
code"
class="
java"
>
android.content.Context;
android.graphics.Canvas;
android.graphics.drawable.Drawable;
android.view.KeyEvent;
android.view.View;
Zoom
View
private
Drawable
image;
int
zoomControler=20;
Zoom(Context
context)
super(context);
image=context.getResources().getDrawable(R.drawable.icon);
setFocusable(true);
protected
onDraw(Canvas
canvas)
//
TODO
Auto-generated
method
stub
super.onDraw(canvas);
//here
u
can
control
width
and
height
of
images........
this
line
very
important
image.setBounds((getWidth()/2)-zoomControler,
(getHeight()/2)-zoomControler,
(getWidth()/2)+zoomControler,
(getHeight()/2)+zoomControler);
image.draw(canvas);
boolean
onKeyDown(int
keyCode,
KeyEvent
event)
if(keyCode==KeyEvent.KEYCODE_DPAD_UP)//
zoom
in
zoomControler+=10;
if(keyCode==KeyEvent.KEYCODE_DPAD_DOWN)
out
zoomControler-=10;
if(zoomControler<
10)
zoomControler=10;
invalidate();
return
true;
packagecom.min.Test_Gallery;
importandroid.app.Activity;
importandroid.graphics.Bitmap;
importandroid.graphics.BitmapFactory;
importandroid.graphics.Color;
importandroid.graphics.Matrix;
importandroid.os.Bundle;
importandroid.util.DisplayMetrics;
importandroid.util.Log;
importandroid.view.GestureDetector;
importandroid.view.KeyEvent;
importandroid.view.MotionEvent;
importandroid.view.View;
importandroid.view.GestureDetector.OnGestureListener;
importandroid.view.View.OnTouchListener;
importandroid.widget.Button;
importandroid.widget.FrameLayout;
importandroid.widget.ImageView;
importandroid.widget.LinearLayout;
importandroid.widget.Toast;
publicclassDisplayImageextendsActivityimplementsOnTouchListener,OnGestureListener{
privatestaticfinalStringTAG="
DisplayImage"
;
privatestaticfinalintFLING_MIN_DISTANCE=100;
privatestaticfinalintFLING_MIN_VELOCITY=200;
/*相关变量声明*/
privateImageViewmImageView;
privateButtonmButton01;
privateButtonmButton02;
privateFrameLayoutlayout1;
privateLinearLayoutlayoutImage;
privateBitmapbmp;
privateintid=0;
privateintdisplayWidth;
privateintdisplayHeight;
privatefloatscaleWidth=1;
privatefloatscaleHeight=1;
privateGestureDetectormGestureDetector;
/**Calledwhentheactivityisfirstcreated.*/
@Override
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
/*加载display.xmlLayout*/
setContentView(R.layout.display);
/*取得屏幕分辨率大小*/
DisplayMetricsdm=newDisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
displayWidth=dm.widthPixels;
displayHeight=dm.heightPixels;
/*初始化相关变量*/
Bundlebundle=this.getIntent().getExtras();
IntegerimageId=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(newButton.OnClickListener(){
@Override
publicvoidonClick(Viewv){
small();
}
});
/*放大按钮onClickListener*/
mButton02.setOnClickListener(newButton.OnClickListener(){
@Override
big();
}
}
//用户轻触触摸屏,由1个MotionEventACTION_DOWN触发
publicbooleanonDown(MotionEvente){
//TODOAuto-generatedmethodstub
//Toast.makeText(this,"
onDown"
Toast.LENGTH_SHORT).show();
onDown..."
returnfalse;
}
/*用户按下触摸屏、快速移动后松开,由1个MotionEventACTION_DOWN,
*多个ACTION_MOVE,1个ACTION_UP触发
*参数解释:
*e1:
第
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Android zoom 放大 缩小 图片 参考 模板
![提示](https://static.bdocx.com/images/bang_tan.gif)