In XML you can do:
android:layout_above="@+id/foo"
to make a element be above another element foo
.
How do I do this programatically?
While RelativeLayout.LayoutParams
can add the rule RelativeLayout.ABOVE
that does not allow me to specify which element I want my view to be above.
that does not allow me to specify which element I want my view to be above.
Sure it does
[From the docs](http://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams.html#addRule(int, int))
anchor The id of another view to use as an anchor, or a boolean value (represented as TRUE for true or 0 for false). For verbs that don't refer to another sibling (for example, ALIGN_WITH_PARENT_BOTTOM) just use -1.
There are two addRule()
methods in the docs. Just use the one which takes a second param and give the id of the View
you want it anchored above.
In fact, the one which you mention, explicitly says
This method should only be used for constraints that don't refer to another sibling
(emphasis mine)