diff --git a/sample/src/main/java/com/arasthel/spannedgridlayoutmanager/sample/MainActivity.kt b/sample/src/main/java/com/arasthel/spannedgridlayoutmanager/sample/MainActivity.kt index e3ae383..3566f6d 100755 --- a/sample/src/main/java/com/arasthel/spannedgridlayoutmanager/sample/MainActivity.kt +++ b/sample/src/main/java/com/arasthel/spannedgridlayoutmanager/sample/MainActivity.kt @@ -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 diff --git a/spannedgridlayoutmanager/src/main/java/com/arasthel/spannedgridlayoutmanager/SpannedGridLayoutManager.kt b/spannedgridlayoutmanager/src/main/java/com/arasthel/spannedgridlayoutmanager/SpannedGridLayoutManager.kt index d462ea9..dd1bddf 100755 --- a/spannedgridlayoutmanager/src/main/java/com/arasthel/spannedgridlayoutmanager/SpannedGridLayoutManager.kt +++ b/spannedgridlayoutmanager/src/main/java/com/arasthel/spannedgridlayoutmanager/SpannedGridLayoutManager.kt @@ -108,6 +108,11 @@ open class SpannedGridLayoutManager(val orientation: Orientation, */ var itemOrderIsStable = false + /** + * Custom height of item + */ + var mCustomHeight : Int = 0 + //============================================================================================== // ~ Initializer //============================================================================================== @@ -195,6 +200,10 @@ open class SpannedGridLayoutManager(val orientation: Orientation, } } + fun setCustomHeight(height: Int) { + this.mCustomHeight = height + } + /** * Measure child view using [RectsHelper] */ @@ -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'")