简体   繁体   English

你怎么能做一个 Get Random 从 url 获取图像?

[英]How could you do a Get Random to get images from a url?

I am making an application and I want one of the Fragments to have an ImageView and the image to be taken from a URL that connects to my VPS.我正在制作一个应用程序,我希望其中一个片段具有 ImageView 和从连接到我的 VPS 的 URL 获取的图像。 I would like you to tell me how can I take a random url from the img folder of the url https://imagerandom.com/img (that url is an example) and project it to ImageView I would like you to tell me how can I take a random url from the img folder of the url https://imagerandom.com/img (that url is an example) and project it to ImageView

Method 1方法一

If you already have a bunch of images you can follow below steps:-如果您已经有一堆图像,您可以按照以下步骤操作:-

1)first import the all images in the file/code. 1)首先导入文件/代码中的所有图像。

2)then store their names in the array or list of string/integer depending upon the name type. 2)然后根据名称类型将它们的名称存储在字符串/整数的数组或列表中。

3)then uses the random function to generate index of list/array. 3)然后使用随机 function 生成列表/数组的索引。

4)then store the random index in some variable and you can use that to have a random images. 4)然后将随机索引存储在某个变量中,您可以使用它来获得随机图像。

Method 2方法二

On internet a lot of websites are available for generating random pictures在互联网上有很多网站可用于生成随机图片

I used "picsum" and help me a lot in various web application for testing我在各种 web 应用程序测试中使用了“picsum”并帮助了我很多

Link for the site:-网站链接:-

https://picsum.photos/ https://picsum.photos/

hope you gonna love it !!希望你会喜欢它!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM