title: Layout looking weird after marshmallow version
body: <p>Hiii,
       I am working on custom layout. It's working perfectly on lollipop and below versions of android but later version showing weird look.</p>
  
  <p>How I want and showing in &lt;= Android 5 </p>
  
  <p><a href="https://i.stack.imgur.com/71SSL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/71SSL.png" alt="enter image description here"></a></p>
  
  <p>How it's getting shown in >Android 5
  <a href="https://i.stack.imgur.com/s1Qxq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/s1Qxq.png" alt="enter image description here"></a></p>
  
  <p>Here is the sketch layout of layout structure.
  <a href="https://i.stack.imgur.com/GfRjT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GfRjT.png" alt="enter image description here"></a></p>
  
  <p>Here is the code for it</p>
  
  <pre><code>public class TableListView extends LinearLayout {
  
  private final ViewGroup headerLinearLayout;
  
  public TableListView(final Context context) {
      this(context, null);
  }
  
  public TableListView(final Context context, final AttributeSet attributeSet) {
      super(context, attributeSet);
  
      setOrientation(LinearLayout.VERTICAL);
  
      final ViewsCreator viewsCreator = new ViewsCreator();
      headerLinearLayout = viewsCreator.createHeaderViews(context, attributeSet);
      columnNameIndices = viewsCreator.getColumnNameIndexMap();
  
      addView(headerLinearLayout);
      addView(listView);
  }
  
  private static class ViewsCreator {
      private final Map&lt;String, Integer&gt; columnNameIndices = new HashMap&lt;String, Integer&gt;();
  
      private ViewsCreator() {
      }
  
      public ViewGroup createHeaderViews(final Context context, final AttributeSet attributeSet) {
          final HeaderView.HeaderParams headerParams = new HeaderView.HeaderParams(context, attributeSet);
          final LinearLayout headerLinearLayout = new LinearLayout(context);
          headerLinearLayout.setOrientation(LinearLayout.HORIZONTAL);
  
          final int numberOfColumns = headerParams.getNumOfColumns();
  
          for (int i = 0; i &lt; numberOfColumns; ++i) {
              final String headerName = headerParams.headerNames[i].toString();
              headerLinearLayout.addView(new HeaderView(context, headerParams, i, headerName));
              columnNameIndices.put(headerName, i);
          }
  
          final ViewTreeObserver viewTreeObserver = headerLinearLayout.getViewTreeObserver();
          final ViewsCreatorOnPreDrawListener preDrawListener = new ViewsCreatorOnPreDrawListener(headerLinearLayout);
          viewTreeObserver.addOnPreDrawListener(preDrawListener);
  
          return headerLinearLayout;
      }
  
      public Map&lt;String, Integer&gt; getColumnNameIndexMap() {
          return columnNameIndices;
      }
  
      private static class ViewsCreatorOnPreDrawListener implements ViewTreeObserver.OnPreDrawListener {
          private final ViewGroup viewGroup;
          private int largestHeaderHeight = 0;
  
          public ViewsCreatorOnPreDrawListener(final ViewGroup viewGroup) {
              this.viewGroup = viewGroup;
          }
  
          @Override
          public boolean onPreDraw() {
              final ViewTreeObserver viewTreeObserver = viewGroup.getViewTreeObserver();
  
              viewTreeObserver.removeOnPreDrawListener(this);
  
              final int childCount = viewGroup.getChildCount();
              for (int i = 0; i &lt; childCount; ++i) {
                  final View childHeaderView = viewGroup.getChildAt(i);
  
                  final int height = childHeaderView.getHeight();
                  if (largestHeaderHeight &lt; height) {
                      largestHeaderHeight = height;
                  }
              }
  
              for (int i = 0; i &lt; childCount; ++i) {
                  final View childHeaderView = viewGroup.getChildAt(i);
  
                  final ViewGroup.LayoutParams layoutParams = childHeaderView.getLayoutParams();
                  layoutParams.height = largestHeaderHeight;
              }
  
              return false;
          }
      }
  }
  
  /**
   * Represents a header in this {@link TableListView}.
   */
  private static class HeaderView extends RelativeLayout {
      private ImageView ivIcon;
      private TextView tvName;
      private ImageView ivArrow;
  
      public HeaderView(final Context context, final HeaderParams headerParams, final int index, final String name) {
          super(context);
          setGravity(Gravity.CENTER);
          setBackgroundResource(headerParams.headerBackground);
          setLayoutParams(
                  new LinearLayout.LayoutParams(0, headerParams.headerHeight, headerParams.headerWeights[index]));
  
          addNameView(context, headerParams, name);
          addArrowView(context, headerParams);
          addIconView(context, headerParams, index);
      }
  
      private void addArrowView(final Context context, final HeaderParams headerParams) {
          ivArrow = new ImageView(context);
          this.addView(ivArrow);
          ivArrow.setId(R.id.iv_header_arrow);
          final RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) ivArrow.getLayoutParams();
          params.addRule(RelativeLayout.RIGHT_OF, android.R.id.title);
          params.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
          params.leftMargin = context.getResources().getDimensionPixelSize(R.dimen.pixel_2dp);
          params.width = context.getResources().getDimensionPixelSize(R.dimen.pixel_9dp);
          params.height = context.getResources().getDimensionPixelSize(R.dimen.pixel_8dp);
          ivArrow.setScaleType(ImageView.ScaleType.FIT_XY);
          ivArrow.setLayoutParams(params);
          setArrowResIds(headerParams.headerArrowUp, headerParams.headerArrowDown);
      }
  
      private void addIconView(final Context context, final HeaderParams headerParams, final int index) {
          if (headerParams.headerIconIndexes.indexOf(index) &gt;= 0) {
              ivIcon = new ImageView(context);
              this.addView(ivIcon);
              ivIcon.setImageResource(headerParams.headerIcon);
              final LayoutParams params = (LayoutParams) ivIcon.getLayoutParams();
              params.addRule(RelativeLayout.LEFT_OF, android.R.id.title);
              params.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
              params.rightMargin = context.getResources().getDimensionPixelSize(R.dimen.pixel_2dp);
              ivIcon.setLayoutParams(params);
          }
      }
  
      private void addNameView(final Context context, final HeaderParams headerParams, final String name) {
          tvName = new TextView(context);
          this.addView(tvName);
          tvName.setId(android.R.id.title);
          tvName.setText(name);
          tvName.setTextColor(context.getResources().getColor(headerParams.headerTextColor));
          tvName.setTextSize(TypedValue.COMPLEX_UNIT_PX, headerParams.headerTextSize);
          if (!TextUtils.isEmpty(headerParams.headerTypeface)) {
              final Typeface typeface =
                      FontManager.getInstance().getFontByName(headerParams.headerTypeface.toString());
              tvName.setTypeface(typeface, Typeface.BOLD);
          } else {
              tvName.setTypeface(Typeface.DEFAULT_BOLD);
          }
          final RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) tvName.getLayoutParams();
          params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
          params.width = ViewGroup.LayoutParams.WRAP_CONTENT;
          params.height = ViewGroup.LayoutParams.MATCH_PARENT;
          tvName.setGravity(Gravity.CENTER);
          tvName.setLayoutParams(params);
      }
  
      private static class HeaderParams {
          private final CharSequence[] headerNames;
          private final float[] headerWeights;
          private final int headerHeight;
          private final int headerBackground;
          private final int headerArrowUp;
          private final int headerArrowDown;
          private final int headerIcon;
          private final List&lt;Integer&gt; headerIconIndexes = new ArrayList&lt;&gt;();
          private final int headerTextColor;
          private final CharSequence headerTypeface;
          private final int headerTextSize;
  
          public HeaderParams(final Context ctx, final AttributeSet attributeSet) {
              final TypedArray typedArray = ctx.obtainStyledAttributes(attributeSet, R.styleable.TableListView);
  
              headerNames = typedArray.getTextArray(R.styleable.TableListView_headerNameArray);
  
              final CharSequence[] weightsArr = typedArray.getTextArray(R.styleable.TableListView_headerWeightArray);
              headerWeights = new float[weightsArr.length];
              for (int i = 0; i &lt; weightsArr.length; i++) {
                  headerWeights[i] = Float.valueOf(weightsArr[i].toString());
              }
  
              headerHeight = typedArray.getDimensionPixelSize(R.styleable.TableListView_headerHeight,
                                                              ViewGroup.LayoutParams.WRAP_CONTENT);
              headerBackground = typedArray.getResourceId(R.styleable.TableListView_headerBackground, 0);
              headerArrowUp = typedArray.getResourceId(R.styleable.TableListView_headerArrowUp, 0);
              headerArrowDown = typedArray.getResourceId(R.styleable.TableListView_headerArrowDown, 0);
              headerIcon = typedArray.getResourceId(R.styleable.TableListView_headerIcon, 0);
  
              final CharSequence[] iconIndexes = typedArray.getTextArray(R.styleable.TableListView_headerIconIndexes);
              if (iconIndexes != null) {
                  for (final CharSequence iconIndex : iconIndexes) {
                      headerIconIndexes.add(Integer.valueOf(iconIndex.toString()));
                  }
              }
  
              headerTextColor = typedArray.getResourceId(R.styleable.TableListView_headerTextColor, R.color.white);
              headerTypeface = typedArray.getText(R.styleable.TableListView_headerTypeface);
  
              final int defSize = ctx.getResources().getDimensionPixelSize(R.dimen.pixel_8dp);
              headerTextSize = typedArray.getDimensionPixelSize(R.styleable.TableListView_headerTextSize, defSize);
              typedArray.recycle();
          }
      }
  }
  }
  </code></pre>
  
  <p>Need help on this.</p>