Skip to content

Instantly share code, notes, and snippets.

@itmammoth
Created August 12, 2018 07:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itmammoth/f8bbf787c6854932d45a23961617d23a to your computer and use it in GitHub Desktop.
Save itmammoth/f8bbf787c6854932d45a23961617d23a to your computer and use it in GitHub Desktop.
スクロールしない高さ自動調整のListView ref: https://qiita.com/itmammoth/items/ba84711e646f625c98e0
class NonScrollListView : ListView {
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
init {
isVerticalScrollBarEnabled = false
isHorizontalScrollBarEnabled = false
}
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
val customHeightMeasureSpec = View.MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE shr 2, View.MeasureSpec.AT_MOST)
super.onMeasure(widthMeasureSpec, customHeightMeasureSpec)
layoutParams.height = measuredHeight
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment