一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

android ListView中嵌套GridView不完全显示如何解决

时间:2015-01-02 编辑:简简单单 来源:一聚教程网

项目需要,在ListView中显示多张图片,用到了GridView,不过如果使用普通的GridView,Item仅仅只是显示一部分,超出第一行以后的都无法显示了,这个很无语,所以又得继承下GridView重写onMeasure方法去测量子控件的宽高了..

这里只是贴出自定义GridView的代码,直接在xml中使用,ListView的Adapter中调用即可:

 代码如下 复制代码
public class GridViewForListView extends GridView {
    public GridViewForListView(Context context) {
        super(context);

    }

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

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
                MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, expandSpec);
    }
}

热门栏目