@Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    int n = getChildCount();
    for (int i = 0; i < n; i++) measureView(getChildAt(i));
  }
 private void addAndMeasureChild(int i, View v) {
   LayoutParams params = v.getLayoutParams();
   if (params == null) {
     params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
   }
   addViewInLayout(v, 0, params, true);
   mChildViews.append(i, v); // Record the view against it's adapter index
   measureView(v);
 }