最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時(shí)間:2017年08月24日 10:58:37   作者:danielinbiti  
這篇文章主要介紹了Android開(kāi)發(fā)之底圖局部加載移動(dòng)的方法,涉及Android針對(duì)圖片與屏幕屬性的讀取、計(jì)算、設(shè)置等相關(guān)操作技巧,需要的朋友可以參考下

本文實(shí)例講述了Android開(kāi)發(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開(kāi)發(fā)入門與進(jìn)階教程》、《Android調(diào)試技巧與常見(jiàn)問(wèn)題解決方法匯總》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)

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

相關(guān)文章

最新評(píng)論

准格尔旗| 东乌珠穆沁旗| 鲁山县| 垫江县| 格尔木市| 本溪市| 临朐县| 甘洛县| 时尚| 西乌珠穆沁旗| 海丰县| 淳化县| 曲麻莱县| 镇安县| 青河县| 亚东县| 天祝| 宜兰县| 孙吴县| 田阳县| 富顺县| 嘉禾县| 蒙城县| 西乌珠穆沁旗| 宜兰县| 陆丰市| 龙江县| 元朗区| 南木林县| 什邡市| 宁海县| 青海省| 库车县| 崇义县| 祁连县| 汨罗市| 且末县| 寻乌县| 西安市| 安吉县| 天等县|