Giter VIP home page Giter VIP logo

Comments (4)

fondesa avatar fondesa commented on May 24, 2024

This library doesn't do anything on item's height but the offset could change only the item's width. Maybe the middle item has a different width from the others and the height you are using is based on the width?

from recycler-view-divider.

kjsolo avatar kjsolo commented on May 24, 2024

Edit: fix wrong number on picture

This is my solution

object : DividerOffsetProvider {
    override fun getOffsetFromSize(grid: Grid, divider: Divider, dividerSide: Side, size: Int): Int {
        if (divider.isTopDivider || divider.isBottomDivider || divider.isStartDivider || divider.isEndDivider) return size
        val gridOrientation = grid.orientation
        if (gridOrientation.isVertical && dividerSide == Side.TOP || gridOrientation.isHorizontal && dividerSide == Side.START) return 0
        if (gridOrientation.isVertical && dividerSide == Side.BOTTOM || gridOrientation.isHorizontal && dividerSide == Side.END) return size

        val sideDividerSize = 16.dp

        val cellsCount = grid.lines[divider.originY].cellsCount
        if (cellsCount >= 3) {
            val fixedSize = (cellsCount - 2) * sideDividerSize
            val allocatableSize = size * (cellsCount - 1) - fixedSize
            val averageSize = allocatableSize / cellsCount.toFloat()

            if (divider.originX == 1 && dividerSide == Side.END
                || divider.originX == cellsCount - 1 && dividerSide == Side.START) {
                return averageSize.toInt()
            } else {
                val middleCellDividerSize = (sideDividerSize + averageSize) / 2
                return middleCellDividerSize.toInt()
            }
        } else {
            return size
        }
    }
}

WX20200609-164430@2x

from recycler-view-divider.

fondesa avatar fondesa commented on May 24, 2024

Perfect, you are probably the first one using the new DividerOffsetProvider API 🥇

from recycler-view-divider.

kjsolo avatar kjsolo commented on May 24, 2024

You can consider passing sideDividerSize as a argument to the OffsetProvider, Make the library easier :)

from recycler-view-divider.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.