我想知道如何调整编辑文本的高度来调整字体大小。我的意思是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