How to lay out Views in RelativeLayout programmatically?

I’m trying to achieve the following programmatically (rather than declaratively via XML): <RelativeLayout…> <TextView … android:id=”@+id/label1″ /> <TextView … android:id=”@+id/label2″ android:layout_below: “@id/label1” /> </RelativeLayout> In other words, how do I make the second TextView appear below the first one, but I want to do it in code: RelativeLayout layout = new RelativeLayout(this); TextView label1 = … Read more

How to programmatically set the layout_align_parent_right attribute of a Button in Relative Layout?

I have a relative layout which I am creating programmatically: RelativeLayout layout = new RelativeLayout( this ); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); Now I have two buttons which I want to add in this relative layout. But the problem is both buttons are being shown on the left of the RelatiiveLayout overlapping on each … Read more