2

I have a statically defined relative layout with height set to wrap_content.

I add several children to it dynamically. This appears just fine.

I now have to add a few more children and line them up above previously added children. This sort of works. (Note: I can only do this once those previously added children have actually been added, as my new children depend on their width.)

I can only see the changes if I change layout height to say 50dp vs wrap_content.

I tried calling invalidate(), postInvalidate() and requestLayout() on the holding layout, but that didn't work. What am I not doing?

public void layOutExtras(CustomView section) {
    if (section.isUnderlined()) {
        int labelOrientation = section.getLabelOrientation();
        View line = createLine(labelOrientation, section.getMeasuredWidth(), section.getId());
        addView(line);
    }
}

private View createLine(int orientation, int width, int viewId) {
    RelativeLayout.LayoutParams params = new LayoutParams(width, 4);
    params.addRule(ABOVE, viewId);
    params.addRule(ALIGN_RIGHT, viewId);
    View line = new ImageView(context);
    line.setBackgroundColor(Color.RED);
    line.setLayoutParams(params);
    return line;
}
Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
Vas
  • 2,014
  • 3
  • 22
  • 38
  • You can certainly make updates to views programmatically. That happens all the time. But you haven't really said what you're trying to do, shown your layouts, or screenshots that show what you expect is different than what actually happens. – Doug Stevenson Feb 11 '16 at 02:30

1 Answers1

0

Sounds like the issue I had a few days ago. The issue is probably due to the height not getting set right. Try setting the minimum height of both the new view and the container you're modifying.

Community
  • 1
  • 1
flakes
  • 21,558
  • 8
  • 41
  • 88