写了一个Layout ,最外层 是一个ScrollView ,包含有 GridView 和其他的组件。
但运行结果发现GridView 只有一行,并且在Layout 的GridView 控件前有一个 黄色感叹号
:The vertically scrolling ScrollView should not contain another vertically scrolling widget (GridView)
解决方式:重写一个MyGridView
public class MyGridView extends GridView { public MyGridView(Context context) { super(context); // TODO Auto-generated constructor stub } public MyGridView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // TODO Auto-generated constructor stub } public MyGridView(Context context, AttributeSet attrs) { super(context, attrs); // TODO Auto-generated constructor stub } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { // TODO Auto-generated method stub int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, expandSpec); } }
接着有几个问题:
1. onMearsure 什么时候被调用
2. MeasureSpec类 的作用
接着 下一遍日志 记录。