本文主要是介绍j2ME中 lwuit实现按钮缩放功能代码解析,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
http://blog.allove.org/archives/j2me-lwuit-image-scale.html (源址)
LWUIT UI
当用户按下按钮的时候 实现缩放功能
final Button b = new Button(NameList[i], unselectedImages[i]) {
public Image getPressedIcon() {
Image i = getIcon();
return i.scaled((int) (i.getWidth() * 0.8), (int) (i.getHeight() * 0.8));
}
};
LWUIT Image 实现代码
public Image scaled(int width, int height) {
if(width == getWidth() && height == getHeight()) {
return this;
}
Dimension d = new Dimension(width, height);
Image i = getCachedImage(d);
if(i != null) {
return i;
}
i = new Image(this.image);
i.scale(width, height);
i.transform = this.transform;
cacheImage(d, i);
return i;
}
获得图片缓冲
Image getCachedImage(Dimension size) {
if(scaleCache != null) {
WeakReference w = (WeakReference)scaleCache.get(size);
if(w != null) {
return (Image)w.get();
}
}
return null;
}
这篇关于j2ME中 lwuit实现按钮缩放功能代码解析的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!