国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 系統(tǒng) > Android > 正文

Android開發(fā)之底圖局部加載移動(dòng)的方法示例

2019-12-12 02:11:31
字體:
供稿:網(wǎ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刷新即可。

對(duì)于觸摸移動(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é)

希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 青龙| 合作市| 同心县| 普定县| 泰安市| 独山县| 兴安县| 廉江市| 郧西县| 汽车| 岑溪市| 木兰县| 叶城县| 浮梁县| 阿克苏市| 咸丰县| 康乐县| 拉萨市| 尚志市| 剑阁县| 黔西县| 商城县| 茂名市| 濉溪县| 潼南县| 凤庆县| 曲靖市| 拜泉县| 巫溪县| 克什克腾旗| 达州市| 体育| 锡林郭勒盟| 苏尼特右旗| 济源市| 米泉市| 瑞丽市| 泗水县| 沙湾县| 金堂县| 东宁县|