EDIT:
I would try with the XML below (you, of course, update the identifier, etc.). The "magic" in xml is that it evenly distributes the entire available width among the TextView (and the EditText in the second line).
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="TextView 01" android:id="@+id/textView01" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <EditText android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="TextView 01" android:id="@+id/editText01" /> </LinearLayout> </LinearLayout>
In your Java code, you can access your EditText views, for example:
EditText editText01 = (EditText) findViewById(R.id.editText01); editText01.setText("1");
Now I have ignored the fact that you need to create your EditText programmatically. Do you really, really have to create them in Java? (Why?)
OLD ANSWER:
If you just want to set the layout fields in your EditText view, I can say that you can use the setMargins(left, top, right, bottom) function call in the setMargins(left, top, right, bottom) variable.
int left = 6; int top = 12; int right = 6; int bottom = 6; TableRow.LayoutParams params = new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); params.setMargins(left, top, right, bottom); EditText edXY = new EditText(inventory.this); edXY.setLayoutParams(params);
If you ultimately want to evenly distribute all available space among six EditText views in a row of a table, I would suggest you look at the following message: 2-column TableLayout with 50% for each column exactly
dbm
source share