4

I created a field of buttons in my XML file:

<RelativeLayout...>
<Button  
    android:id="@+id/button_1"
    ...
    />
<Button  
    android:id="@+id/button_2"
    android:layout_toRightOf="@+id/button_1"  
...
/>
...
</RelativeLayout>enter code here

Now I want to abolish the XML rule "toRightOf" programmaticaly. I know how to set rules:

RelativeLayout.LayoutParams params = null;
params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.RIGHT_OF, topIcon.getId());
button_2.setLayoutParams(params);

But I want to DELETE rules I had set in XML file. How can this be done?

The background of my question: I used an XML file to easily create field of buttons. But later I want to drag and drop buttons. For that I have to delete rules like "toRightOf". Otherwise instead of one button a lot of buttons move if I only want to move one button.

KWT
  • 233
  • 2
  • 3
  • 12

1 Answers1

4

Looking at this question, it cannot be removed but instead you set the value to 0:

layoutParams.addRule(RelativeLayout.RIGHT_OF, 0);
Community
  • 1
  • 1
Ricky
  • 7,785
  • 2
  • 34
  • 46
  • 2
    As of API level 17, the class RelativeLayout.LayoutParams has the following method: public void removeRule (int verb) – Roger Rapid Mar 06 '13 at 15:47