画布内可点击的图像
我在 android 中创建了一个画布,里面有多个位图图像。我不想让这些图像能够单击。
到目前为止我已经尝试过以下操作..
我尝试在图像视图中添加位图,因为 imageview 有一个 setOnClickListner 但我认为 ImageView 不能添加到 Canvas 中,所以我放弃了这个想法。因为即使Bitmap本身也没有点击事件。
I have create a canvas in android and inside that i have multiple bitmap images.not i want to make these images click able.
I have tried following things so far..
I tried to add bitmap in image view as imageview has a setOnClickListner
but i think ImageView can't be added into Canvas , so i dropped this idea. because even Bitmap itself has no click events.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您想使用 Canvas,请记住它是一种低级绘图机制。
因此,您需要自己实现点击逻辑。
您还必须将所有图像的坐标和相应的 onClickListeners 保存在内存中的某个位置。
其他解决方案:
使用布局(可能是相对布局),在其中添加 ImageView 作为子项。
If you want to use Canvas, keep in mind that it is a low level drawing mechanism.
Therefore, you need to implement the click logic yourself.
You also have to keep the coordinates of all images and the corresponding onClickListeners somewhere in memory.
Other solution:
Use a Layout, possibly a RelativeLayout, in which you add the ImageViews as children.
我相信您正在要求类似的东西:
现在您有了用您自己的话“将整个视图设置为壁纸”的背景,然后您就有了可点击的图像。在您的代码中,您实现 onClickListener 并将其附加到您的 ImageView,它将执行您想要它执行的任何操作。
I believe you're asking for something like that:
Now you have your background "setting the whole view as a wallpaper" in your own words, and then you have your image, which is clickable. In your code you implement onClickListener and attach it to your ImageView and it will do whatever you want it to do.