我想知道如何調整編輯文本的高度來調整字體大小。我的意思是editText總是一樣高,不管我是否將fontSize更改爲5sp或保留默認值。當然,我可以使用類似這樣:將EditText調整爲字體大小
<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>
,但我也想伸展,如果有超過10行。我該怎麼做?
[編輯]:
好吧,我解決它以這樣的方式
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) {
}
});
好吧,也許例子可以幫助HTTP://dl.dropbox .com/u/18780140/edittexts.png當然在任何地方都有layout_height =「wrap_content」。問題是爲什麼「10sp editText」與默認的高度相同 – 2012-02-11 10:28:25