For adding a RelativeLayout
attribute whose value is true or false use 0
for false and RelativeLayout.TRUE
for true:
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) button.getLayoutParams()
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE)
It doesn't matter whether or not the attribute was already added, you still use addRule(verb, subject)
to enable/disable it. However, post-API 17 you can use removeRule(verb)
which is just a shortcut for addRule(verb, 0)
.