I have a problem with the layout. What am I doing:
- create a TableLayout in xml with null children:
<TableLayout android:id="@+id/t_layout_contents"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/l_layout_tags"
android:stretchColumns="1"
android:paddingLeft="5dip"
android:paddingRight="5dip" /> - Insert the first line programmatically in onCreate ():
TableLayout tLayoutContents = (TableLayout)findViewById(R.id.t_layout_contents);
NoteElement nr_1 = new NoteElement(this);
tLayoutContents.addView(nr_1);
The "NoteElement" class extends TableRow. The first line consists of an empty ImageView as a placeholder and an EditText for text input. The NoteElement constructor is as follows:
public NoteElement(Context c) {
super(c);
this.context = c;
defaultText = c.getResources().getString(R.string.create_note_help_text);
imageView = new ImageView(context);
imageView.setImageResource(android.R.color.transparent);
LayoutParams params = new LayoutParams(0);
imageView.setLayoutParams(params);
addView(imageView);
addView(addTextField());
}
The addTextField () method specifies the attributes of the EditText widget:
private EditText addTextField() {
editText = new EditText(context);
editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
editText.setMinLines(4);
editText.setRawInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE);
editText.setHint(R.string.create_note_et_blank_text);
editText.setAutoLinkMask(Linkify.ALL);
editText.setPadding(5, 0, 0, 0);
editText.setGravity(Gravity.TOP);
editText.setVerticalScrollBarEnabled(true);
LayoutParams params = new LayoutParams(1);
editText.setLayoutParams(params);
return editText;
}
So far so good. But my problem arises as soon as the free space for characters is exhausted. EditText does not resize, but switches to a single line of EditText. I am desperately looking for a way in which EditText dynamically changes to its height, being dependent on the inserted text length.
?