In my xml I have:
<RelativeLayout
android:id="@+id/mainWeek"
android:layout_height="387dip"
android:layout_width="match_parent"
android:layout_marginTop="5dip">
<RelativeLayout
android:id="@+id/day1"
android:layout_marginTop="5dip"
android:layout_marginLeft="5dip"
android:layout_marginRight="5dip"
android:layout_height="50dip"
android:layout_width="match_parent">
...
</RelativeLayout>
</RelativeLayout>
in code I want something like:
RelativeLayout layout = new RelativeLayout(this);
RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
rlp.addRule(RelativeLayout.BELOW, R.id.day1);
rlp.addRule(RelativeLayout.ALIGN_LEFT, R.id.day1);
TextView tv1 = new TextView(this);
tv1.setText("A");
layout.addView(tv1);
this.addContentView(layout, rlp);
but the “layout” and its “tv1” appears on the top of the screen and not in below the “day1”.
What am I doing wrong?
Thanks
Maybe you actually want the add the
layoutview to theRelativeLayoutidentified by the idmainWeek:With the method
addContentView()(i think) you append the layout view directly to the main window.