mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
minor possible fixes to span of autofit recycler
This commit is contained in:
parent
d28c70d3ff
commit
39b860f4c8
2 changed files with 5 additions and 2 deletions
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue