解决方案就是写个子类,重写onMeasure方法即可:
自定义ExpandableListView的子类:
package jp.oikura.app.widget
import android.content.Context
import android.util.AttributeSet
import android.widget.ExpandableListView
internal class CustomNestedExpandableListView : ExpandableListView {
constructor(context: Context?) : super(context)
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
public override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
val heightMeasureSpecCustom = MeasureSpec.makeMeasureSpec(
Int.MAX_VALUE shr 2, MeasureSpec.AT_MOST)
super.onMeasure(widthMeasureSpec, heightMeasureSpecCustom)
val params = layoutParams
params.height = measuredHeight
}
}
ScrollView无法滚动的代码:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/gray