我目前有一个计时器,可以滴答作响并更改标签以倒计时秒数。 这是可能的,如果可以的话,我如何将图像和图像框中的图像更改为每个的自定义值 标签=1 imagebox1=1.jpg 标签=2 imagebox1=2.jpg 或者关闭计时器刻度值会更容易吗?
最佳答案
我会创建一个 Sprite 类。然后,我将使用股票行情指示器中的值来循环浏览我需要的各种位图。但如果图像足够小,分辨率将它们合并在一个图像中并使用 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() 会将目标切换到新帧,因此您将 Sprite 绘制为
canvas.drawBitmap(sprite.bitmap, sprite.source, sprite.target, null);
关于java - Android 将自定义图像设置为标签文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9609124/