Android GridView自适应Item高度

 

http://www.eoeandroid.com/forum.php?mod=viewthread&tid=246995&ctid=200

当GridView外面有ScrollView时, GridView只显示一行Item的高度,

为使GridView跟所有Item高度一致使用这个GridVew替换就可以.

public class NoScroolGridView extends GridView {

    public NoScroolGridView(Context context) {
        super(context);
    }

    public NoScroolGridView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public NoScroolGridView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    //不出现滚动条
    @Override
    public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

        int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, expandSpec);
    }
}

 

 

你可能感兴趣的:(Android GridView自适应Item高度)