Skip to content
Advertisement

Android Java Set up recyclerview items that are right aligned

I am developing an android chat app and I would like the messages of the user you are chatting with to be aligned to the right and their messages to be aligned to the left. This is the condition that allows you to distinguish who the message belongs to, I can only write it on the bindview holder:

JavaScript

But how do I align the item to the right or left?

I have also thought about inflating two different layouts but I should go and operate in the CreateViewHolder in which I would not have the model.getUidSender value. How can I solve this problem?

This is my complete code:

JavaScript

Advertisement

Answer

I managed to solve it like this:

JavaScript

So, this is the chat card layout:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement