Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
196 views
in Technique[技术] by (71.8m points)

android - How do I make RecyclerView update its layout?

I have a RecyclerView with a bunch of custom views which may change height after a while, because they contain ImageViews which load their image asynchronously. The RecyclerView does not pick up on this layout change, although I call forceLayout on the ImageView, and the RecyclerView is initialized with setHasFixedSize(false). All container-parents of the ImageView have set android:layout_height="wrap_content".

How can I make the RecyclerView update its layout? With good'ol ListView this was not a problem.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use the notifyDataSetChanged in the Adapter for the RecyclerView if all your images change at the same time or notifyItemChanged(int position) if only one of the items has changed. This will tell the RecyclerView to rebind the particular View.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...