浏览 2029 次
该帖已经被评为隐藏帖
|
|
---|---|
作者 | 正文 |
发表时间:2009-10-10
最后修改:2009-10-10
以下内容Sinfrancis版权所有,专注请注明来自 http://mdev.cc/dev
Hi ben, it is very easy to Zoom in and zoom out Images. take a look here
zooming.java
import android.app.Activity; import android.os.Bundle; public class zooming extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(new Zoom(this)); } } Zoom.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); } @Override protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub super.onDraw(canvas); //here u can control the width and height of the images........ this line is very important image.setBounds((getWidth()/2)-zoomControler, (getHeight()/2)-zoomControler,(getWidth()/2)+zoomControler, (getHeight()/2)+zoomControler); image.draw(canvas); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if(keyCode==KeyEvent.KEYCODE_DPAD_UP)// zoom in zoomControler+=10; if(keyCode==KeyEvent.KEYCODE_DPAD_DOWN) // zoom out zoomControler-=10; if(zoomControler<10) zoomControler=10; invalidate(); return true; } } 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |