黑莓5.0 api图像遮罩/背景图像位置
我刚刚开始学习开发黑莓应用程序,但遇到了一些障碍。我不确定如何移动比它所应用的字段/管理器大的背景图像。这是一张图片来说明我的意思:
到目前为止,我已尝试添加位图 到 AbsolutePositionManager 内的 BitmapField ,我认为我可以设置绝对管理器的大小,然后在其中移动位图字段。事实并非如此,管理只是获取其中内容的大小:(
我来自前端 Web 开发背景,所以我正在寻找的是行为类似于 css 中的“background-position”属性的东西或某种图像掩码。
--更新
--
这是我现在有一个自定义大小的管理器,可以显示较大的 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); } }
I've just started learning to develop blackberry apps and I've hit a bit of a snag. I'm unsure how I could move around a background image that is large than the field/manager it is being applied to. Here's an image to illustrate what I mean:
So far I have tried adding a Bitmap to a BitmapField inside a AbsolutePositionManager thinking I would be able to set the size of the absolute manager and just move the bitmapfield around inside it. That isn't the case, the manage just takes the size of the content inside it :(
I come from a frontend web dev background so what I'm looking for is something that behaves similar to the 'background-position' attribute in css or some sort of image mask.
Thanks in advance!
-- update --
This is a code sample of where I have got to. I now have a custom sized manager that displays a chunk of a larger BitmapField. I just need a way to move that BitmapField around.
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); } }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
无需将其添加为字段,只需将对其的引用存储在管理器中的某个位置,然后自己绘制即可。这是一个未经测试的示例:
现在您只需将 x_offset 和 y_offset 设置为您想要的任何值,它就会被移动。如果您需要调整管理器的大小以适应位图,请添加:
希望这会有所帮助!
Rather than adding it as a Field, just store a reference to it somewhere in your Manager and then paint it yourself. Here's an untested example:
Now you can just set x_offset and y_offset to whatever you want and it'll be shifted. If you need to mess with the size of the Manager to fit the Bitmap, add:
Hope this helps!