GridView 布局与自定义可高度自适应的代码

GridView xml中的代码

<cn.zhiup.mobile.main.allcourse.WrapHeightGridView
        android:id="@+id/typeName"
        android:background="@color/white"
        android:verticalSpacing="@dimen/x15"
        android:numColumns="3"
        android:paddingBottom="@dimen/x20"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
复制代码

自定义GridView代码

import android.content.Context
import android.util.AttributeSet
import android.widget.GridView
class WrapHeightGridView(context: Context, attrs:AttributeSet): GridView(context,attrs) {
    override fun onMeasure(widthMeasureSpec:Int,heightMeasureSpec:Int){
        var expandSpec:Int = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE/2,MeasureSpec.AT_MOST)
        super.onMeasure(widthMeasureSpec, expandSpec);
    }
}

复制代码
© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享