将位图添加到 Android 中的视图

发布于 2024-12-29 22:29:31 字数 625 浏览 2 评论 0原文

我有一个看法,收到者: (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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

书间行客 2025-01-05 22:29:31

我决定使用 SimView 而不是 ImageView,它解决了所有问题。感谢您的帮助!

I decided to use a SimView instead of an ImageView, it solved all the problems. Thanks for the help!

救星 2025-01-05 22:29:31

您只能将一个bitmap关联到一个ImageView,这是一对一的映射。

如果您希望将另一张图片叠加在现有图像之上,那么您需要将它们都放在 FrameLayout 中。

此外,如果较小的位图位于不同的 ImageView 中(充当两个不同的 UI 元素),那么稍后您将更容易在其周围移动。

示例伪 xml

<RelativeLayout fill parent>
    <FrameLayout fill parent>
         <ImageView center in parent>
         <ImageView align bottom right = true>
    </FrameLayout>
</RelativeLayout>

You can only associate one bitmap to one ImageView, 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

<RelativeLayout fill parent>
    <FrameLayout fill parent>
         <ImageView center in parent>
         <ImageView align bottom right = true>
    </FrameLayout>
</RelativeLayout>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文