I'm wondering how to adjust height of edit text to te font size. I mean editText is always same hight no matter if i change fontSize to 5sp or leave default. Of course i could use something like this:
<EditText
android:id="@+id/msgInput"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:inputType="textMultiLine"
android:textSize="14sp"
android:hint="@string/hintMsgInput">
</EditText>
but i also want to stretch if there are more than 1 line. How can i do it?
[EDIT]:
Ok,i solved it in this way:
msgInput = (EditText) findViewById(R.id.msgInput);
msgInput.addTextChangedListener(new TextWatcher()
{
public void afterTextChanged(Editable s) {
if (msgInput.getLineCount() > 1)
{
msgInput.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
}
else
{
int height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 40, getResources().getDisplayMetrics());
msgInput.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, height));
}
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
public void onTextChanged(CharSequence s, int start, int before,
int count) {
}
});
Check this
<EditText
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/editText1"
android:textSize="5sp"
android:inputType="textMultiLine"
android:text="hello h r u hello h r u hello h r u hello h r u hello h r u "
></EditText>
set edit text height as wrap_content
android:layout_height="wrap_content"
You are providing 20 dp constraint to the height of EditText. It you want the textView to adjust the height in regard of Text size use
android:layout_height="wrap_content"
Also by default single line is false. Which ensures multiple line true.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With