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

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

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

2019-10-22 18:29:25
字體:
供稿:網(wǎng)友

本文實例講述了Android開發(fā)之底圖局部加載移動的方法。分享給大家供大家參考,具體如下:

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+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刷新即可。

對于觸摸移動只是坐標(biāo)計算方式不同,其它都類似。另外擴充到GIS等,可以根據(jù)小圖片粘貼實現(xiàn)局部加載內(nèi)容。

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


注:相關(guān)教程知識閱讀請移步到Android開發(fā)頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 石家庄市| 新闻| 乡宁县| 安吉县| 宁陵县| 洪湖市| 平度市| 昌平区| 瑞安市| 三门峡市| 苏尼特右旗| 当雄县| 阜南县| 乌拉特前旗| 应城市| 通化市| 深泽县| 应用必备| 乌什县| 南川市| 苏州市| 峨山| 湖南省| 塘沽区| 栾川县| 黑山县| 奉贤区| 庆城县| 克拉玛依市| 确山县| 綦江县| 叙永县| 和平县| 晋江市| 赣州市| 睢宁县| 沾化县| 满洲里市| 勃利县| 金秀| 晋中市|