![](/img/trans.png)
[英]Unable to load Array List of image URLs from Picasso using Recycler View Adapter. But directly able to load from Url string
[英]How to load image from Url in Recycler view
我是android新手,我想知道如何在Recycler視圖中從URL
加載圖像,並輕松定義從URL
加載圖像時Bitmap
及其功能的用途。 我不想使用任何第三方庫。 請為此提供解決方案。
您的問題似乎有點不清楚要么您要求使用URL或其他任何內容閱讀圖像。 如果是這樣,您可以像這樣讀取圖像並將其設置為ImageView
InputStream in = (InputStream) new URL(imageUrl).getContent(); //Reads whatever content found with the given URL Asynchronously And returns.
Bitmap bitmap = BitmapFactory.decodeStream(in); //Decodes the stream returned from getContent and converts It into a Bitmap Format
yourImageView.setBitmap(bitmap); //Sets the Bitmap to ImageView
in.close(); //Closes the InputStream
其中imageUrl
是一個完整的URL,指向您的圖像,如something.com/image1.jpg
我想你已經有了字符串URL。 請參考此鏈接位圖鏈接此處此方法可以在onBindViewHolder()內聲明。
正如他們所說的那樣,你應該使用第三方庫。 您可以在這里選擇它們https://android-arsenal.com/
我建議Glide: http : //inthecheesefactory.com/blog/get-to-know-glide-recommended-by-google/en
我找到了問題的答案,我使用Asynctask加載多個URL來從url加載圖像,而不使用第三方libarires。 下載發生在后台線程中。 這減少了主UI線程的工作,並在后台線程上並行運行下載運行,並且位圖的結果在onPostExecute()方法上傳遞。該方法最終可以在OnBindViewHolder上傳遞,以將圖像綁定到其各自的視圖。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.