如何在JetPack组成中将图像从一个合成功能传递到另一个函数?
我正在开发一个带有文本和图像的应用程序。图像在一个可复合的(活动)上与文本旁边看起来很小,例如缩略图。这个想法是:当用户触摸(单击)图像时,导航组件将用户带到另一个合并(活动)中的图像的全屏幕版本。有可能吗?如果是,怎么样?提前致谢。
I am developing an app with texts and images. The images appear small, like thumbnails, on one composable (activity), alongside the text. The idea is: when the user touches (clicks) the image, the navigation component takes the user to a full screen version of this image in another composable (activity). Is it at al possible? If yes, how? Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该传递某些内容以识别图像,而不是传递图像本身。例如:
r.drawable.your_image
);资产
文件夹或某些远程URL,则应通过Imageuri
(即/path_in_assets/your_image
或> https://foo.bar/your_image
)。然后,从“ ListActivity”中,您可以使用
Intent
Extras将图像ID传递给下一个活动。在“详细信息”中,在
ongreate
方法的内部,您将获得图像ID并正确加载它...最后,在合并中,您可以使用以下方式加载基于资源ID的图像:
或使用< a href =“ https://coil-kt.github.io/coil/compose/”
Instead of passing the image itself, you should pass something to identify the image. For instance:
R.drawable.your_image
);assets
folder or some remote URL, you should pass the imageUri
(i.e./path_in_assets/your_image
orhttps://foo.bar/your_image
).Then from the "ListActivity" you can pass the image ID to next activity using the
Intent
extras.in "DetailsActivity", inside of the
onCreate
method, you will get image ID and load it properly...finally, in your composable, you can load an image based on resource ID using:
or using Coil for URL resource: