1
我目前有一個計時器,可以打勾並更改標籤以倒計時秒數。 是可能的,如果是的話,我如何改變和圖像和圖像框中的每個自定義值例如 Label = 1 imagebox1 = 1.jpg Label = 2 imagebox1 = 2.jpg 或者它會更容易去掉計時器滴答值?Android從標籤文本中設置自定義圖像
我目前有一個計時器,可以打勾並更改標籤以倒計時秒數。 是可能的,如果是的話,我如何改變和圖像和圖像框中的每個自定義值例如 Label = 1 imagebox1 = 1.jpg Label = 2 imagebox1 = 2.jpg 或者它會更容易去掉計時器滴答值?Android從標籤文本中設置自定義圖像
我會做一個Sprite類。然後我會使用ticker的值循環遍歷我需要的各種位圖。但是,如果圖像是足夠小的分辨率將它們組合在一個圖像,並使用AniSprite ...
import android.graphics.*;
public class AniSprite {
public RectF target;
public Rect source;
public Bitmap bitmap;
public int width;
public int height;
public float posx;
public float posy;
public int frames;
public int curframe = 0;
public AniSprite(Bitmap bitmap, float posx, float posy, int width, int height, int frames) {
this.drawview = drawview;
this.bitmap = bitmap;
this.width = width;
this.height = height;
this.posx = posx;
this.posy = posy;
this.frames = frames;
source = new Rect(curframe * width, 0, (curframe * width) + width, height);
target = new RectF(posx, posy, posx + (width), posy + (height));
}
public void animate() {
curframe++;
if(curframe >= frames){
curframe = 0;
}
source = new Rect(curframe, 0, (curframe) + width, height);
}
public void setSourceRect(Rect rect) {
source = rect;
curframe = rect.right/width;
}
public void ChangePos(float posx, float posy) {
this.posx = posx;
this.posy = posy;
source = new Rect(curframe * width, 0, (curframe * width) + width, height);
target = new RectF(posx, posy, posx + (width), posy + (height));
}
}
所以在這個類,而不是通過不同的位圖循環,我做了有動畫的每一幀的一大位圖相繼。 (使用Photoshop)參數指示屏幕x和y上的位置,框架的寬度和高度(以及每個圖像)以及幀數。
執行AniSprite.animate()將目標切換到新的框架,因此你畫你的精靈作爲
canvas.drawBitmap(sprite.bitmap, sprite.source, sprite.target, null);