I have a RecyclerView
with a bunch of custom views which may change height after a while, because they contain ImageView
s which load their image as
Google has finally fixed this in support library v23.2. Issue is fixed by updating this line in build.gradle
after updating your support repository with the SDK Manager:
compile 'com.android.support:recyclerview-v7:23.2.0'
int wantedPosition = 25; // Whatever position you're looking for
int firstPosition = linearLayoutManager.findFirstVisibleItemPosition(); // This is the same as child #0
int wantedChild = wantedPosition - firstPosition;
if (wantedChild < 0 || wantedChild >= linearLayoutManager.getChildCount()) {
Log.w(TAG, "Unable to get view for desired position, because it's not being displayed on screen.");
return;
}
View wantedView = linearLayoutManager.getChildAt(wantedChild);
mlayoutOver =(LinearLayout)wantedView.findViewById(R.id.layout_over);
mlayoutPopup = (LinearLayout)wantedView.findViewById(R.id.layout_popup);
mlayoutOver.setVisibility(View.INVISIBLE);
mlayoutPopup.setVisibility(View.VISIBLE);
This code is worked for me.
I had the same problem, I just set a fix width and height for the ImageView. Try that and see where you get. You can also use a lib for this, I use Square Picasso and I got it working with RecyclerView.
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
.
Call the notifyDataSetChanged()
or notifyItemChanged(int position)
methods of the RecyclerView.Adapter
from the MAIN THREAD. Calling it from an AsyncTask
may result in the main thread not updating the ImageView
s. Its most convenient to have a callback method in the activity/fragment work as a listener, and have it called by the AsyncTask
in onPostExecute()