将位图添加到 Android 中的视图
我有一个看法,收到者: (ImageView) findViewById(R.id.photo)
该视图当前有一个位图。我想在角落添加另一个位图。位图是通过 v.getDrawingCache() 从我当前所在的侦听器中检索的。现在我有一个代码可以完全替换“照片”视图中的图像:
OnClickListener mImageListener = new OnClickListener() {
public void onClick(View v) {
v.buildDrawingCache();
((ImageView) findViewById(R.id.photo)).setImageBitmap(v.getDrawingCache());
}
};
有人知道如何添加图像吗? 在仍然使用 XML 视图时绘制位图的答案 由于某种原因并没有真正为我工作:( 注意:我添加的位图稍后将使用 MoveListener 或其他东西移动。以防万一这很重要......
I have a vew, received by:
(ImageView) findViewById(R.id.photo)
That view currently has a bitmap on it. I want to add another bitmap, at the corner. The bitmap is retreieved by v.getDrawingCache(), from the listener I am currently in.Right now I have a code that completely replaces the image in the 'photo' view:
OnClickListener mImageListener = new OnClickListener() {
public void onClick(View v) {
v.buildDrawingCache();
((ImageView) findViewById(R.id.photo)).setImageBitmap(v.getDrawingCache());
}
};
Doesanyone know how to just add the image? The answer on Draw Bitmap When Still Using XML View
didn't really work for mefor some reason :(
Note: The bitmap I am adding will be moved around later on using a MoveListener or something. Just in case that was important...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我决定使用 SimView 而不是 ImageView,它解决了所有问题。感谢您的帮助!
I decided to use a SimView instead of an ImageView, it solved all the problems. Thanks for the help!
您只能将一个
bitmap
关联到一个ImageView
,这是一对一的映射。如果您希望将另一张图片叠加在现有图像之上,那么您需要将它们都放在
FrameLayout
中。此外,如果较小的位图位于不同的 ImageView 中(充当两个不同的 UI 元素),那么稍后您将更容易在其周围移动。
示例伪 xml
You can only associate one
bitmap
to oneImageView
, it is a one to one mapping.If you want another picture overlay'ed on top of the existing image then you will need to have both of them within a
FrameLayout
.Also it will be easier for you to move around the smaller bitmap later on if it is in a different
ImageView
, acts as two different UI elements.Sample pseudo xml