Charles Galvez Charles Galvez - 1 year ago 95
Android Question

Recyclerview 2 Different Layouts

So I'm making an application that has 2 different layouts inside a only one RecyclerView.

I can do that, but my problem is,

I want to set the size of "A"(Please look at the pic below) to take 70% of screen size.

And "B" to take 30% of the screen.

I Know how to work with weight_sum/layout_weight but I can't think of anything

that will work for this.

enter image description here

Answer Source

You can get screen height in that case and pass it to your recyclerview adapter.

Use getItemViewType() for two different layouts.

and in OnCreateViewHolder() while creating view set heights to view as per your requirements. It will work.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download