Android中如何实现底图局部加载移动-创新互联
这篇文章主要介绍“Android中如何实现底图局部加载移动”,在日常操作中,相信很多人在Android中如何实现底图局部加载移动问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”Android中如何实现底图局部加载移动”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
10余年的南阳网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。成都全网营销的优势是能够根据用户设备显示端的尺寸不同,自动调整南阳建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。成都创新互联从事“南阳网站设计”,“南阳网站推广”以来,每个客户项目都认真落实执行。具体代码如下:
public class MapMgr { public static MapMgr mapMgr = null; private int map_num = 28; private int b_x = 0; private int b_y = 0; private int width = 0; private int height = 0; private Bitmap bmpView = null; //create by danielinbiti,前提,你图片确实比屏幕大,如果不比屏幕大,下面注释行修改一下即可。 public static void init(int width,int height){ if(mapMgr==null){ mapMgr = new MapMgr(width,height); } } public static MapMgr getInstance(){ return mapMgr; } public MapMgr(int width,int height){ this.width = width; this.height = height; Bitmap bmp = PicMgr.getInstance().getBackGroundBitmap(); b_x = (bmp.getWidth()-width)/2;//保证图片比屏幕大 b_y = (bmp.getHeight()-height)/2; bmpView = Bitmap.createBitmap(bmp, b_x, b_y, width, height); } public void logic(){ } public void mapDown(){ Bitmap bmp = PicMgr.getInstance().getBackGroundBitmap(); if(b_y+heightbmp.getHeight()){ b_y = bmp.getHeight() - height; } } bmpView = Bitmap.createBitmap(bmp, b_x, b_y, width, height); } public void mapUp(){ Bitmap bmp = PicMgr.getInstance().getBackGroundBitmap(); if(b_y>0){ b_y = b_y - bmp.getHeight()/map_num; if(b_y<0){ b_y = 0; } } bmpView = Bitmap.createBitmap(bmp, b_x, b_y, width, height); } public void mapLeft(){ Bitmap bmp = PicMgr.getInstance().getBackGroundBitmap(); if(b_x>0){ b_x = b_x - bmp.getWidth()/map_num; if(b_x<0){ b_x = 0; } } bmpView = Bitmap.createBitmap(bmp, b_x, b_y, width, height); } public void mapRight(){ Bitmap bmp = PicMgr.getInstance().getBackGroundBitmap(); if(b_x+width bmp.getWidth()){ b_x = bmp.getHeight() - width; } } bmpView = Bitmap.createBitmap(bmp, b_x, b_y, width, height); } public void draw(Canvas canvas){ Paint paint = new Paint(); if(bmpView!=null){ canvas.drawBitmap(bmpView,0, 0, paint); } } }
调用
public void onKeyDownDeal(int keyCode){ if(keyCode==KeyEvent.KEYCODE_DPAD_UP){ MapMgr.getInstance().mapUp(); }else if(keyCode==KeyEvent.KEYCODE_DPAD_DOWN){ MapMgr.getInstance().mapDown(); }else if(keyCode==KeyEvent.KEYCODE_DPAD_LEFT){ MapMgr.getInstance().mapLeft(); }else if(keyCode==KeyEvent.KEYCODE_DPAD_RIGHT){ MapMgr.getInstance().mapRight(); } }
到此,关于“Android中如何实现底图局部加载移动”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注创新互联网站,小编会继续努力为大家带来更多实用的文章!
分享文章:Android中如何实现底图局部加载移动-创新互联
网站地址:http://lswzjz.com/article/dspepi.html