I have a RecyclerView ViewHolder
for a RelativeLayout
. In my OnBindViewHolder
method, I'm updating the height of the entire layout and a contained ImageView, based on a condition. This works fine, however, this new layout is being recycled for subsequent views that don't meet the condition. Thus, producing inconsistent results.
// Involves populating data into the item through holder
@Override
public void onBindViewHolder(RallyAdapter.ViewHolder viewHolder, final int position) {
//Expand viewholder and thumbnail if rally name takes up multiple lines
if(rally.getName().length() > 23) {
RelativeLayout.LayoutParams relParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
//Original height is 114
relParams.height = 139
//where 'relativeLayout' is referencing the base layout
viewHolder.relativeLayout.setLayoutParams(relParams);
RelativeLayout.LayoutParams imgParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
//Original height is 117
imgParams.height = 143
viewHolder.thumbnail.setLayoutParams(imgParams);
} else {
//Need code here to reset layout and thumbnail to original heights
}
}
I know I have to have an else to my condition because I'm in the onBindViewHolder
function but I just don't know what it's supposed to be.