亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Android實現(xiàn)在屏幕上移動圖片的方法

 更新時間:2015年06月16日 17:16:03   作者:紅薯  
這篇文章主要介紹了Android實現(xiàn)在屏幕上移動圖片的方法,實例分析了Android操作圖片的相關(guān)技巧,需要的朋友可以參考下

本文實例講述了Android實現(xiàn)在屏幕上移動圖片的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:

1. Speed.java文件:

package net.obviam.droidz.model.components;
public class Speed {
  public static final int DIRECTION_RIGHT = 1;
  public static final int DIRECTION_LEFT = -1;
  public static final int DIRECTION_UP  = -1;
  public static final int DIRECTION_DOWN = 1;
  private float xv = 1;  // velocity value on the X axis
  private float yv = 1;  // velocity value on the Y axis
  private int xDirection = DIRECTION_RIGHT;
  private int yDirection = DIRECTION_DOWN;
  public Speed() {
    this.xv = 1;
    this.yv = 1;
  }
  public Speed(float xv, float yv) {
    this.xv = xv;
    this.yv = yv;
  }
  public float getXv() {
    return xv;
  }
  public void setXv(float xv) {
    this.xv = xv;
  }
  public float getYv() {
    return yv;
  }
  public void setYv(float yv) {
    this.yv = yv;
  }
  public int getxDirection() {
    return xDirection;
  }
  public void setxDirection(int xDirection) {
    this.xDirection = xDirection;
  }
  public int getyDirection() {
    return yDirection;
  }
  public void setyDirection(int yDirection) {
    this.yDirection = yDirection;
  }
  // changes the direction on the X axis
  public void toggleXDirection() {
    xDirection = xDirection * -1;
  }
  // changes the direction on the Y axis
  public void toggleYDirection() {
    yDirection = yDirection * -1;
  }
}

2. main.java文件:

public void run() {
  Canvas canvas;
  Log.d(TAG, "Starting game loop");
  while (running) {
    canvas = null;
    // try locking the canvas for exclusive pixel editing
    // in the surface
    try {
      canvas = this.surfaceHolder.lockCanvas();
      synchronized (surfaceHolder) {
        // update game state
        this.gamePanel.update();
        // render state to the screen
        // draws the canvas on the panel
        this.gamePanel.render(canvas);
      }
    } finally {
      // in case of an exception the surface is not left in
      // an inconsistent state
      if (canvas != null) {
        surfaceHolder.unlockCanvasAndPost(canvas);
      }
    }  // end finally
  }
}
public void update() {
  // check collision with right wall if heading right
  if (droid.getSpeed().getxDirection() == Speed.DIRECTION_RIGHT
      && droid.getX() + droid.getBitmap().getWidth() / 2 >= getWidth()) {
    droid.getSpeed().toggleXDirection();
  }
  // check collision with left wall if heading left
  if (droid.getSpeed().getxDirection() == Speed.DIRECTION_LEFT
      && droid.getX() - droid.getBitmap().getWidth() / 2 <= 0) {
    droid.getSpeed().toggleXDirection();
  }
  // check collision with bottom wall if heading down
  if (droid.getSpeed().getyDirection() == Speed.DIRECTION_DOWN
      && droid.getY() + droid.getBitmap().getHeight() / 2 >= getHeight()) {
    droid.getSpeed().toggleYDirection();
  }
  // check collision with top wall if heading up
  if (droid.getSpeed().getyDirection() == Speed.DIRECTION_UP
      && droid.getY() - droid.getBitmap().getHeight() / 2 <= 0) {
    droid.getSpeed().toggleYDirection();
  }
  // Update the lone droid
  droid.update();
}

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

相關(guān)文章

  • Android項目遷移到AndroidX的方法步驟

    Android項目遷移到AndroidX的方法步驟

    這篇文章主要介紹了Android項目遷移到AndroidX的方法步驟,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-12-12
  • Android小米推送簡單使用方法

    Android小米推送簡單使用方法

    這篇文章主要為大家詳細(xì)介紹了Android小米推送簡單使用方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-01-01
  • Android仿微博個人詳情頁滾動到頂部的實例代碼

    Android仿微博個人詳情頁滾動到頂部的實例代碼

    這篇文章主要介紹了Android仿微博個人詳情頁滾動到頂部的實例代碼,本文通過實例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒家,需要的朋友可以參考下
    2019-05-05
  • android?studio實現(xiàn)上傳圖片到j(luò)ava服務(wù)器

    android?studio實現(xiàn)上傳圖片到j(luò)ava服務(wù)器

    這篇文章主要為大家詳細(xì)介紹了android?studio實現(xiàn)上傳圖片到j(luò)ava服務(wù)器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-08-08
  • Android實現(xiàn)自動截圖腳本

    Android實現(xiàn)自動截圖腳本

    這篇文章主要為大家詳細(xì)介紹了Android實現(xiàn)自動截圖腳本,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-01-01
  • 淺析KJFrameForAndroid框架如何高效加載Bitmap

    淺析KJFrameForAndroid框架如何高效加載Bitmap

    Bitmap是Android系統(tǒng)中的圖像處理的最重要類之一。用它可以獲取圖像文件信息,進行圖像剪切、旋轉(zhuǎn)、縮放等操作,并可以指定格式保存圖像文件。本文主要是從KJFrameForAndroid框架中分析高效加載Bitmap的方法
    2014-07-07
  • Android開發(fā)獲取手機內(nèi)網(wǎng)IP地址與外網(wǎng)IP地址的詳細(xì)方法與源碼實例

    Android開發(fā)獲取手機內(nèi)網(wǎng)IP地址與外網(wǎng)IP地址的詳細(xì)方法與源碼實例

    這篇文章主要介紹了Android獲取本機內(nèi)網(wǎng)IP地址與外網(wǎng)IP地址源碼實例,需要的朋友可以參考下
    2020-03-03
  • Android小程序?qū)崿F(xiàn)個人信息管理系統(tǒng)

    Android小程序?qū)崿F(xiàn)個人信息管理系統(tǒng)

    這篇文章主要為大家詳細(xì)介紹了Android小程序?qū)崿F(xiàn)個人信息管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-05-05
  • Android開發(fā)中Activity屬性設(shè)置小結(jié)

    Android開發(fā)中Activity屬性設(shè)置小結(jié)

    Android應(yīng)用開發(fā)中會經(jīng)常遇到Activity組件的使用,下面就來講解下Activity組件。Activity的生命周期、通信方式和IntentFilter等內(nèi)容,并提供了一些日常開發(fā)中經(jīng)常用到的關(guān)于Activity的技巧和方法。通過本文,你可以進一步了接Android中Activity的運作方式。
    2015-05-05
  • android仿知乎ScrollView滾動改變標(biāo)題欄透明度

    android仿知乎ScrollView滾動改變標(biāo)題欄透明度

    這篇文章主要為大家詳細(xì)介紹了android仿知乎ScrollView滾動改變標(biāo)題欄透明度,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-06-06

最新評論