将GridView添加到Android中的ListView中

问题描述:

我试图创建一个ListView,它将包含两种类型的元素:字符串和GridView。
I.e.将两个字符串和一个GridView放在一个ListView中。将GridView添加到Android中的ListView中

版面看起来应该是这样的:

  • 字符串项目1.1
  • 字符串项目1.2
  • 字符串项目1.3
  • 字符串项目1.4
  • GridView的项目1个的GridView项目2
    GridView的第3项的GridView项目4
  • 字符串项目2.1
  • 字符串项目2.2
  • 字符串项目2.3
  • 字符串项目2.4

有没有办法做到这一点?

按照现在我只能显示GridView中的第一个项目,它只是ListView中的常规String元素。

的代码可以在这里看到:

任何帮助表示赞赏:)

要回答我的问题:

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

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(); 
    } 
} 
+8

我欠你一个六包,这完美的作品! :) – 2013-11-14 23:26:47

+0

+1谢谢你!你救了我的一天!再次感谢好友。 – Sajmon 2014-06-04 18:03:43

+0

非常感谢...你是真正的MVP – DiegoAlt 2014-08-30 17:01:18