set listview height programmatically android

Solutions on MaxInterview for set listview height programmatically android by the best coders in the world

showing results for - "set listview height programmatically android"
Fabio
30 Oct 2019
1import android.content.Context
2import android.util.AttributeSet
3import android.view.View.MeasureSpec
4import android.widget.ListView
5
6
7class SuggestionList : ListView {
8    constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) {}
9    constructor(context: Context?) : super(context) {}
10    constructor(context: Context?, attrs: AttributeSet?, defStyle: Int) : super(
11        context,
12        attrs,
13        defStyle
14    ) {
15    }
16
17    override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
18        val expandSpec = MeasureSpec.makeMeasureSpec(
19            Int.MAX_VALUE shr 2,
20            MeasureSpec.AT_MOST
21        )
22        super.onMeasure(widthMeasureSpec, expandSpec)
23    }
24}