Android中如何实现底图局部加载移动
这篇文章主要介绍“Android中如何实现底图局部加载移动”,在日常操作中,相信很多人在Android中如何实现底图局部加载移动问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”Android中如何实现底图局部加载移动”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
创新互联建站是一家集网站建设,洋县企业网站建设,洋县品牌网站建设,网站定制,洋县网站建设报价,网络营销,网络优化,洋县网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。
具体代码如下:
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://abwzjs.com/article/pgjdcs.html