Reputation: 1389
This is not a design question, I have the item designed. I am confused on how to pull it off.
I am tasked with designing a view for Android that has a view of a user's post and the comments under it. The post contains some extra information and widely different design from the comments, but all of them need to scroll in tandem, like a web page would (Oh, how I am spoiled by my years of web dev...).
My current solution is to nest a LinearLayout
(at the top of the view to contain the user's post) and a RecyclerView
(below the post to display the comments) inside a vertical ScrollView
. The information is actually displayed, but the RecyclerView
, of course, scrolls independently of the LinearLayout
above it and ruins the functionality of the view.
I wish, if possible, to keep the RecyclerView
in use
The best case scenario would be to have the LinearLayout with the post scroll a certain amount, and then the RecyclerView
take over. However, I don't want to poison my codebase with 200+ ugly lines of code to achieve this, so if this is a laborious task to complete, I would rather look for alternatives.
Upvotes: 1
Views: 157
Reputation: 1953
The first thing to understand is: do you really need a RecyclerView
, or even better, do you really need recycling?
If the answer is yes, the way to go is two different item types in the RecyclerView
's Adapter
(for more details, see here or here). This concept was already present in the ListView
: the main difference is that RecyclerView
enforce the use of the View Holder pattern. It is not so complex, and, more importantly, is the way the RecyclerView
is supposed to solve that problem. Depending on your UI design, you may also want to have different view types for different types of comments (plain text, images, ...). Remember that, when the RecyclerView
is included in a ScrollView
, the recycling won't work, because all the items in it will be drawn at once to compute the height of the content of the parent ScrollView
.
If the answer is no, then you could just create your views at runtime and add them to a parent LinearLayout
in a ScrollView
. It is really nothing more than a for loop.
A more fancy approach would be to use an ItemDecoration
for the user's post, but I don't see any specific advantage in this case.
Upvotes: 1