Skip to content
This repository has been archived by the owner on Mar 26, 2019. It is now read-only.

Adds custom height #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ class MainActivity: android.support.v7.app.AppCompatActivity() {

setContentView(R.layout.activity_main)

val spannedGridLayoutManager = SpannedGridLayoutManager(orientation = SpannedGridLayoutManager.Orientation.VERTICAL, spans = 4)
val spannedGridLayoutManager = SpannedGridLayoutManager(orientation = SpannedGridLayoutManager.Orientation.VERTICAL, spans = 2)
spannedGridLayoutManager.itemOrderIsStable = true

recyclerview.layoutManager = spannedGridLayoutManager
/**
* if you want use a custom height for item
* spannedGridLayoutManager.setCustomHeight(200)
*/

recyclerview.addItemDecoration(SpaceItemDecorator(left = 10, top = 10, right = 10, bottom = 10))
recyclerview.layoutManager = spannedGridLayoutManager

val adapter = GridItemAdapter()
recyclerview.adapter = adapter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ open class SpannedGridLayoutManager(val orientation: Orientation,
*/
var itemOrderIsStable = false

/**
* Custom height of item
*/
var mCustomHeight : Int = 0

//==============================================================================================
// ~ Initializer
//==============================================================================================
Expand Down Expand Up @@ -195,6 +200,10 @@ open class SpannedGridLayoutManager(val orientation: Orientation,
}
}

fun setCustomHeight(height: Int) {
this.mCustomHeight = height
}

/**
* Measure child view using [RectsHelper]
*/
Expand All @@ -203,7 +212,7 @@ open class SpannedGridLayoutManager(val orientation: Orientation,
val freeRectsHelper = this.rectsHelper

val itemWidth = freeRectsHelper.itemSize
val itemHeight = freeRectsHelper.itemSize
val itemHeight = if(mCustomHeight != null && mCustomHeight!! > 0) mCustomHeight else freeRectsHelper.itemSize

if (view.layoutParams !is SpanLayoutParams) {
throw TypeCastException("View LayoutParams must be of type 'SpanLayoutParams'")
Expand Down