首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在Android中添加GridView到ListView

在Android中添加GridView到ListView
EN

Stack Overflow用户
提问于 2010-10-05 17:13:34
回答 1查看 24.5K关注 0票数 16

我正在尝试创建一个由两种类型的元素组成的ListView :String和GridView。

例如,将字符串和GridView都放在一个ListView中。

布局应如下所示:

  • String项目1.1
  • String项目1.2
  • String项目1.3
  • String项目1.4
  • GridView项目1 GridView项目2

GridView项目3 GridView项目4

  • String项目2.1

  • String项目2.2

  • String项目2.3

  • String项目2.4

有没有办法做到这一点?

现在,我只能显示GridView中的第一项,它的作用就像ListView中的常规String元素一样。

可以在此处查看代码:

如有任何帮助,我们将非常感谢:)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-10-17 17:58:28

回答我自己的问题:

基于this answer,我创建了这个类,它工作得非常好:

代码语言:javascript
复制
public class NonScrollableGridView extends GridView {
    public NonScrollableGridView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        // Do not use the highest two bits of Integer.MAX_VALUE because they are
        // reserved for the MeasureSpec mode
        int heightSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, heightSpec);
        getLayoutParams().height = getMeasuredHeight();
    }
}
票数 52
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3862281

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档