DroidFS/app/src/main/java/sushi/hardcore/droidfs/widgets/NonScrollableColoredBorderL...

26 lines
901 B
Kotlin
Raw Normal View History

2020-07-27 16:20:52 +02:00
package sushi.hardcore.droidfs.widgets
import android.content.Context
import android.util.AttributeSet
import android.widget.ListAdapter
class NonScrollableColoredBorderListView: ColoredBorderListView {
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet): super(context, attrs)
2020-08-05 14:06:54 +02:00
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int): super(context, attrs, defStyleAttr)
fun computeHeight(): Int {
var totalHeight = 0
for (i in 0 until adapter.count){
val item = adapter.getView(i, null, this)
item.measure(0, 0)
totalHeight += item.measuredHeight
}
return totalHeight + (dividerHeight * (adapter.count-1))
}
2020-07-27 16:20:52 +02:00
override fun setAdapter(adapter: ListAdapter?) {
super.setAdapter(adapter)
2020-08-05 14:06:54 +02:00
layoutParams.height = computeHeight()
2020-07-27 16:20:52 +02:00
}
}