BlackBerry- 배경 이미지/애니메이션 림 OS 4.5.0
-
21-09-2019 - |
문제
화면의 배경 이미지를 설정하는 방법과 모든 필드 또는 텍스트에서 애니메이션을 수행하는 방법을 도와주세요.
감사합니다....
해결책
배경 이미지
스크린 클래스에는 a가 있습니다 보호 된 공허 페인트 백 (그래픽 그래픽) 방법.
어떤 이유로 든 화면에서 배경 이미지를 페인트하는 데 직접 사용할 수 없습니다. Catch : Paintbackground Method는 필드 클래스에서 파생되며 ExtricalfieldManager에서 사용할 수 있습니다.
class BgScreen extends MainScreen implements FieldChangeListener {
ButtonField mButton;
public BgScreen(Bitmap background) {
super();
BGVerticalFieldManager manager =
new BGVerticalFieldManager(background);
add(manager);
mButton = new ButtonField("Button", ButtonField.CONSUME_CLICK);
mButton.setChangeListener(this);
manager.add(mButton);
}
public void fieldChanged(Field field, int context) {
if (mButton == field)
Dialog.inform("You pressed button");
}
}
class BGVerticalFieldManager extends VerticalFieldManager {
Bitmap mBgBitmap = null;
int mBgWidth = -1;
int mBgHeight = -1;
int mBgX = -1;
int mBgY = -1;
public BGVerticalFieldManager(Bitmap background) {
super(USE_ALL_WIDTH | USE_ALL_HEIGHT);
mBgBitmap = background;
mBgWidth = mBgBitmap.getWidth();
mBgHeight = mBgBitmap.getHeight();
mBgX = (Display.getWidth() - mBgWidth) >> 1;
mBgY = (Display.getHeight() - mBgHeight) >> 1;
}
protected void paintBackground(Graphics graphics) {
paintBackgroundBitmap(graphics);
super.paintBackground(graphics);
}
private void paintBackgroundBitmap(Graphics graphics) {
if (null != mBgBitmap) {
graphics.drawBitmap(
mBgX, mBgY, mBgWidth, mBgHeight, mBgBitmap, 0, 0);
}
}
}
GIF 애니메이션
GIF 애니메이션을 사용하려면 재정의하십시오 보호 된 빈 공간 페인트 (그래픽 그래픽) 방법과 사용 도로 증분 프레임 인덱스의. 사용 TIMER.SCHEDULEATFIXEDRATE 필드를 무효화하려면 :
class GIFVerticalFieldManager extends VerticalFieldManager {
EncodedImage mGIFImage = null;
int mGIFWidth = -1;
int mGIFHeight = -1;
int mGIFX = -1;
int mGIFY = -1;
int mGIFFrameCount = -1;
int mGIFFrameIndex = -1;
final int mGIFDelay = 30;
public GIFVerticalFieldManager(EncodedImage gifAnimation) {
super(USE_ALL_WIDTH | USE_ALL_HEIGHT);
mGIFImage = gifAnimation;
mGIFWidth = mGIFImage.getWidth();
mGIFHeight = mGIFImage.getHeight();
mGIFX = (Display.getWidth() - mGIFWidth) >> 1;
mGIFY = (Display.getHeight() - mGIFHeight) >> 1;
mGIFFrameCount = mGIFImage.getFrameCount();
mGIFFrameIndex = 0;
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
invalidate();
}
}, mGIFDelay, mGIFDelay);
}
protected void paint(Graphics graphics) {
paintGifAnimation(graphics);
super.paint(graphics);
}
private void paintGifAnimation(Graphics graphics) {
if (null != mGIFImage) {
graphics.drawImage(
mGIFX, mGIFY, mGIFWidth, mGIFHeight,
mGIFImage, mGIFFrameIndex, 0, 0);
mGIFFrameIndex++;
if (mGIFFrameIndex > mGIFFrameCount - 1)
mGIFFrameIndex = 0;
}
}
}
편집하다: 훌륭한 기사 - 직접 화면 도면
제휴하지 않습니다 StackOverflow