首页 文章

黑莓5.0 api图像蒙版/背景图像位置

提问于
浏览
0

我刚开始学习开发黑莓应用程序,但我遇到了一些障碍 . 我不确定如何移动比应用它的字段/管理器大的背景图像 . 这是一张图片来说明我的意思:

enter image description here

到目前为止,我已经尝试在 AbsolutePositionManager 中添加一个 Bitmap ,以为我可以设置绝对管理器的大小,只需在其中移动位图字段 . 情况并非如此,管理只需要内容中的内容大小:(

我来自前端Web开发背景,所以我正在寻找的是类似于css中的'background-position'属性或某种图像掩码的东西 .

提前致谢!

  • 更新 -

这是我所需要的代码示例 . 我现在有一个自定义大小的管理器,显示一个较大的BitmapField块 . 我只需要一种方法来移动BitmapField .

package mypackage;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.container.AbsoluteFieldManager;

public class MyImage extends AbsoluteFieldManager {

    protected void sublayout(int maxWidth, int maxHeight){
        int displayWidth = 326;
        int displayHeight = 79;
        super.sublayout(displayWidth, displayHeight);
        setExtent(displayWidth, displayHeight);
    }

    public MyImage(){
        Bitmap _image = Bitmap.getBitmapResource("img.jpg");
        BitmapField image = new BitmapField(_image);
        add(image);
    }

}

1 回答

  • 0

    而不是将其添加为Field,只需在Manager中的某个位置存储对它的引用,然后自己绘制它 . 这是一个未经测试的例子:

    public class MyManager extends VerticalFieldManager() {
        Bitmap _bg;
        public MyManager() {
            _bg = Bitmap.getBitmapResource("img.jpg");
        }
    
        protected void paint(Graphics graphics) {
            graphics.drawBitmap(x_offset, y_offset, _bg.getWidth(), _bg.getHeight(), _bg, 0, 0);
            super.paint(graphics);
        }
    
    }
    

    现在你可以将x_offset和y_offset设置为你想要的任何东西,它将被移动 . 如果您需要弄乱管理器的大小以适合位图,请添加:

    protected void sublayout(int width, int height) {
        super.sublayout(width, height);
        setExtent(Math.min(width, Math.max(getWidth(), _bg.getWidth())), Math.min(height, Math.max(getHeight(), _bg.getHeight()));
    }
    

    希望这可以帮助!

相关问题