I'm trying to create RecyclerView
item programmatically using Anko library and I want to do all the stuff in one RelativeLayout
for the best perfomance.
The title of my item should be match_parent
, but it shouldn't cover flag marker (hasImportantMessages
) or number on the right (issues counter
), so I'm using this code to adjust RelativeLayout
rules:
with(tvTitle.layoutParams as RelativeLayout.LayoutParams) {
removeRule(START_OF)
removeRule(ALIGN_PARENT_END)
when {
hasImportantMessages -> addRule(START_OF, R.id.iv_important_messages)
issueCounter > 0 -> addRule(START_OF, R.id.tv_issues_counter)
else -> addRule(ALIGN_PARENT_END)
}
}
When RecyclerView creates first visible ViewHolders everything is fine, but when I scroll down a little and RecyclerView starts to reuse it's holders, I got some issues with it, check these screenshots.
As you can see, RelativeLayout rules don't work properly. Title textView overlaps flag marker or issues counter textView. Maybe I should invalidate()
somehow, but I already tried - doesn't work.