i have a problem with an RelativeLayout. I try to create the following with Java-Code:
<RelativeLayout
android:id="@+id/RelativeLayout01"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<CheckBox
android:id="@+id/CheckBox01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:clickable="false" />
<TextView
android:id="@+id/TextView03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="TEXT here"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
The XML from above creates the look i wanna have. Now I’m trying to do this with Java-Code:
// First Child: TextView
text = new TextView(context);
text.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
text.setText(contentText);
text.setTextSize(20);
// Layout-Info for text
RelativeLayout.LayoutParams text_relativeParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
text_relativeParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
text_relativeParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
// Add text to layout:
this.addView(text, text_relativeParams);
// Checkbox
checkbox = new CheckBox(context);
checkbox.setClickable(false);
checkbox.setChecked(reachable);
checkbox.setBackgroundColor(Color.BLUE);
checkbox.setText("");
checkbox.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
// Layout-Info for Checkbox
RelativeLayout.LayoutParams checkbox_relativeParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
checkbox_relativeParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
checkbox_relativeParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
// Adding Checkbox to layout:
this.addView(checkbox);
The Java-Code from above should do the same as the XML. But there is a little difference between should an do. The Checkbox appears on the left side. How do i move the Checkbox to the right? (this is a derived class from RelativeLayout, the code is in the Constructor)
Thanks in advance.
Remove this line of code
Set the layout params of checkbox with checkbox_relativeParams