我正在尝试创建一个由两种类型的元素组成的ListView :String和GridView。
例如,将字符串和GridView都放在一个ListView中。
布局应如下所示:
GridView项目3 GridView项目4
有没有办法做到这一点?
现在,我只能显示GridView中的第一项,它的作用就像ListView中的常规String元素一样。
可以在此处查看代码:
如有任何帮助,我们将非常感谢:)
发布于 2012-10-17 17:58:28
回答我自己的问题:
基于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();
}
}
https://stackoverflow.com/questions/3862281
复制相似问题