78

Prior to API 17, how do I remove a rule from a layout? I have a RelativeLayout with a number of children. The RelativeLayout is the main layout of my activity. After adding the rule programmatically using

RelativeLayout.LayoutParams layout = (LayoutParams) theChild.getLayoutParams();
layout.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);

I need to remove the rule programmatically at some later time. How would I do this assuming earlier API than 17?

Onik
  • 19,396
  • 14
  • 68
  • 91
Cote Mounyo
  • 13,817
  • 23
  • 66
  • 87

2 Answers2

162

Ah, I figure it out.

RelativeLayout.LayoutParams layout = (LayoutParams) myChild.getLayoutParams();
layout.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, 0);

So there is really no removeRule until API 17.

Cote Mounyo
  • 13,817
  • 23
  • 66
  • 87
  • 10
    This answer wasn't immediately clear to me. In Android code, removeRule(rule) basically does the same thing as addRule(rule, 0), which is why the answer shown here works. – greg7gkb Jan 21 '15 at 20:23
  • 1
    @Cote Mounyo but this code now in AS required api level19 how to do in api level below o equal to 16 – Erum Sep 16 '15 at 12:33
0

Depending on the situation, in my case I created new LayoutParams and then added rules which were needed

TheSecond
  • 183
  • 1
  • 1
  • 8