Is it possible to set in Java code (when creating a relative layout at runtime) the equivalent of android:layout_below ?
+3
A:
Yes:
RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
p.addRule(RelativeLayout.BELOW, R.id.below_id);
viewToLayout.setLayoutParams(p);
First the code creates a new layout params by specifying the height and width. The addRule
method adds the equivalent of the xml propery android:layout_below
. Then you just call View#setLayoutParams
on the view you want to have those params.
Qberticus
2010-07-18 21:20:29
Qberticus - thanks very much for the detailed and clear reply. I will check this out.
AlanH
2010-07-19 07:25:31
This works fine for me. Thanks again.
AlanH
2010-07-20 06:00:02