I would like to know how I could dynamically write the data below in Java. I am stuck on how you write the "layout_alignParent" can set the gravity of each text view....
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_alignParentBottom="true"
android:gravity="center_horizontal" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:gravity="center_vertical" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView3"
android:layout_alignBottom="@+id/textView3"
android:layout_alignParentRight="true"
android:gravity="center_vertical" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal" />
I know that the code below would not work. But how could I re-write it for it to work?
RelativeLayout m = (RelativeLayout)findViewById(R.id.tileContainerME);
EditText et1 = new EditText(this);
EditText et2 = new EditText(this);
EditText et3 = new EditText(this);
EditText et4 = new EditText(this);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT,
android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
et1.setLayoutParams(params);
params.removeRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
params.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
et2.setLayoutParams(params);
params.removeRule(RelativeLayout.ALIGN_PARENT_LEFT);
params.removeRule(RelativeLayout.CENTER_VERTICAL);
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
et3.setLayoutParams(params);
params.removeRule(RelativeLayout.ALIGN_PARENT_RIGHT);
params.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
params.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
et4.setLayoutParams(params);
params.removeRule(RelativeLayout.ALIGN_PARENT_TOP);
params.removeRule(RelativeLayout.CENTER_HORIZONTAL);
et1.setGravity(Gravity.CENTER_HORIZONTAL);
et1.setHint("Test");
et2.setGravity(Gravity.CENTER_VERTICAL);
et2.setHint("Test");
et3.setGravity(Gravity.CENTER_VERTICAL);
et3.setHint("Test");
et4.setGravity(Gravity.CENTER_HORIZONTAL);
et4.setHint("Test");
m.addView(et1);
m.addView(et2);
m.addView(et3);
m.addView(et4);