添加一个GridView Android中一个ListView [英] Add a GridView to a ListView in Android

查看:99
本文介绍了添加一个GridView Android中一个ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个ListView这将包括两种类型的元素的。字符串和一个GridView
即把两个字符串和内部单一的ListView一个GridView。

I'm trying to create a ListView that will consist of two types of elements: Strings and a GridView.
I.e. putting both Strings and a GridView inside one single 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
  • String Item 1.1
  • String Item 1.2
  • String Item 1.3
  • String Item 1.4
  • GridView Item 1 GridView Item 2
    GridView Item 3 GridView Item 4
  • String Item 2.1
  • String Item 2.2
  • String Item 2.3
  • String Item 2.4

有没有办法做到这一点?

Is there any way to do this?

根据我现在只能说明在GridView的第一个项目,它的行为就像在ListView一个普通字符串元素。

As per now I can only show the first item in the GridView, and it acts just as a regular String element in the ListView.

在code可以在这里查看:

The code can be viewed here:

  • CustomListViewActivity.java
  • SectionAdapter.java
  • main.xml
  • header_row.xml
  • simple_list_row.xml
  • grid_list_row.xml

任何帮助是AP preciated:)

Any help is appreciated :)

推荐答案

要回答我的问题:

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

这篇关于添加一个GridView Android中一个ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆