簡體   English   中英

如何在“回收者視圖”(網格布局)中顯示圖像?

[英]How to display images in a Recycler View (Grid Layout)?

如何在Recycler視圖(網格布局)中的drawable res文件夾中顯示所有圖像? 如果有它們的話該怎么辦?

我嘗試了常規方法,但效果很好,但當時只有5張圖像。 如何為100張圖像執行相同操作,這是很多工作。

您可以嘗試創建一個可以存儲所有圖像的drawbles數組,然后使用循環顯示所有圖像。

Drawble [] drawables = new Drawable[]{ContextCompat.getDrawable(getActivity(), R.drawable.digit00),ContextCompat.getDrawable(getActivity(),R.drawable.digit01),ContextCompat.getDrawable(getActivity(), R.drawable.digit02));

您還可以使用循環來打印出要放入可繪制數組中的內容,從而節省鍵入的時間。

例如,創建一個循環,將' ContextCompat.getDrawable(getActivity(),R.drawable.digit'+ int') '打印到logcat( int是一個每次都會遞增的int,這就是我說要命名的原因您的可繪制對象的末尾帶有數字,例如digit00-digit99)。 然后,您可以將所有內容復制到您的真實代碼中。

recyclerView.setLayoutManager(new GridLayoutManager(this, numberOfColumns));

並查看圖像,您必須在回收站適配器中使用Picasso

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM