Android開發(fā)之底圖局部加載移動(dòng)的方法示例
本文實(shí)例講述了Android開發(fā)之底圖局部加載移動(dòng)的方法。分享給大家供大家參考,具體如下:
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,前提,你圖片確實(shí)比屏幕大,如果不比屏幕大,下面注釋行修改一下即可。 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+height<bmp.getHeight()){ b_y = b_y + bmp.getHeight()/map_num; if(b_y+height>bmp.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 = b_x + bmp.getWidth()/map_num; 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); } } }
調(diào)用
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(); } }
然后使用線程調(diào)用draw刷新即可。
對于觸摸移動(dòng)只是坐標(biāo)計(jì)算方式不同,其它都類似。另外擴(kuò)充到GIS等,可以根據(jù)小圖片粘貼實(shí)現(xiàn)局部加載內(nèi)容。
更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android圖形與圖像處理技巧總結(jié)》、《Android開發(fā)入門與進(jìn)階教程》、《Android調(diào)試技巧與常見問題解決方法匯總》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)》
希望本文所述對大家Android程序設(shè)計(jì)有所幫助。
- android異步加載圖片并緩存到本地實(shí)現(xiàn)方法
- Android加載大分辨率圖片到手機(jī)內(nèi)存中的實(shí)例方法
- Android實(shí)現(xiàn)加載廣告圖片和倒計(jì)時(shí)的開屏布局
- Android中自定義加載樣式圖片的具體實(shí)現(xiàn)
- Android 異步加載圖片分析總結(jié)
- Android開發(fā)之加載圖片的方法
- Android 異步加載圖片的實(shí)例代碼
- Android使用控件ImageView加載圖片的方法
- Android Glide圖片加載(加載監(jiān)聽、加載動(dòng)畫)
- Android實(shí)現(xiàn)Listview異步加載網(wǎng)絡(luò)圖片并動(dòng)態(tài)更新的方法
相關(guān)文章
Android中RecyclerView實(shí)現(xiàn)滑動(dòng)刪除與拖拽功能
這篇文章主要使用了RecyclerView的ItemTouchHelper類實(shí)現(xiàn)了Item的拖動(dòng)和刪除功能,ItemTouchHelper是v7包下的一個(gè)類,下面來看看詳細(xì)的介紹吧,需要的朋友可以參考學(xué)習(xí)。2017-02-02Flutter進(jìn)階之實(shí)現(xiàn)動(dòng)畫效果(二)
這篇文章主要為大家詳細(xì)介紹了Flutter進(jìn)階之實(shí)現(xiàn)動(dòng)畫效果的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-08-08Android從0到完整項(xiàng)目(1)使用Android studio 創(chuàng)建項(xiàng)目詳解
本篇文章主要介紹了Android從0到完整項(xiàng)目(1)使用Android studio 創(chuàng)建項(xiàng)目詳解,具有一定的參考價(jià)值,有興趣的可以了解一下2017-07-07Android協(xié)程的7個(gè)重要知識點(diǎn)匯總
在現(xiàn)代Android應(yīng)用開發(fā)中,協(xié)程(Coroutine)已經(jīng)成為一種不可或缺的技術(shù),它不僅簡化了異步編程,還提供了許多強(qiáng)大的工具和功能,可以在高階場景中發(fā)揮出色的表現(xiàn),本文將深入探討Coroutine重要知識點(diǎn),幫助開發(fā)者更好地利用Coroutine來構(gòu)建高效的Android應(yīng)用2023-09-09Android?WebView緩存機(jī)制優(yōu)化加載慢問題
我知道你一定在煩惱Android?Webview的性能問題,特別突出的是-加載速度慢、消耗流量,針對Android?Webview的性能問題,提出一些有效解決方案2023-02-02Android Map數(shù)據(jù)結(jié)構(gòu)全面總結(jié)分析
這篇文章主要為大家介紹了Android Map數(shù)據(jù)結(jié)構(gòu)全面總結(jié)分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-12-12