0

Tweet Layout

Say I am making Twitter's Tweet Views. To reduce nesting and maintain a flat hierarchy in the recycler view, I use constraintlayout. The header and footer will be the same for all posts (author, timestamp, likes, retweet button etc), the main_post however will be its own set of views : a poll / repost / image etc.

So I try to reuse the header and footer in all the different types post view resource files, by extracting them into a separate file. Now to do that the header and footer will need to have their own parent views. But then this would increase the depth of the view hierarchy.

There is a solution for this exact problem in android, called the [1]. Great! Now you can include other views into a parent constraintlayout without using a nested constraintlayout everytime!

Except that all constraints defined on the <merge> and the <include> tag, are ignored!! [2]

So is there really no way to reuse layouts without nesting them in viewgroups?

[1] : https://developer.android.com/develop/ui/views/layout/improving-layouts/reusing-layouts#Merge

[2] : https://stackoverflow.com/a/52343338

I tried to use <merge> around my header and footer layouts. But all the constraints simply disappear, be it in the tag or the <include> tag.

Replacing <merge> with <constraintlayout> fixes the issue, but then it increases the depth of the view heirarchy.

xidsyed
  • 1
  • 1
  • 1

0 Answers0