minor possible fixes to span of autofit recycler

This commit is contained in:
Jays2Kings 2022-05-01 16:07:05 -04:00
parent d28c70d3ff
commit 39b860f4c8
2 changed files with 5 additions and 2 deletions

View file

@ -138,6 +138,9 @@ fun Context.contextCompatDrawable(@DrawableRes resource: Int): Drawable? {
val Int.pxToDp: Int
get() = (this / Resources.getSystem().displayMetrics.density).toInt()
val Float.pxToDp: Float
get() = (this / Resources.getSystem().displayMetrics.density)
/**
* Converts to px.
*/

View file

@ -28,7 +28,7 @@ class AutofitRecyclerView @JvmOverloads constructor(context: Context, attrs: Att
var columnWidth = -1f
set(value) {
field = value
if (measuredWidth > 0) {
if (width > 0) {
setSpan(true)
}
}
@ -62,7 +62,7 @@ class AutofitRecyclerView @JvmOverloads constructor(context: Context, attrs: Att
private fun getTempSpan(): Int {
if (spanCount == 0 && columnWidth > 0) {
val dpWidth = (measuredWidth.pxToDp / 100f).roundToInt()
val dpWidth = (measuredWidth.toFloat().pxToDp / 100f).roundToInt()
return max(1, (dpWidth / columnWidth).roundToInt())
}
return 3