简体   繁体   中英

How to add section divider in Recycler-view

Scenario : I am trying to add the section between items in the recycler view. This divider is not with every element but it is based on the datasource. My Datasource has a divider property for that cell it means it is a divider cell and a divider of 2dp*100dp need to be shown in place of the normal cell data.

WorkDone : I tried to do that using two sibling inside the my recycler-view main cell-view which will be passed to the holder. In one sibling there is my main cell layout and in another one just the separator view and based on the datasource while binding I am changing the visibility of the each sibling. But I am facing that while scrolling back and forth multiple separator and coming at random placed and keep on increasing while scrolling.

Question :

  1. Is this is correct way to achieve desired result?
  2. What am i doing wrong ( fix for this?)

Sample UI : As there is divider between Instagram sizes ans Facebook sizes

图片

If you implement these scenario (having two types of holders) in a right way, i think it's the best way to achieve your goal.

After some more google targeted search able to find one solution:

Two view holder for different views.

Most close working solution

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM