【发布时间】:2014-03-12 08:49:12
【问题描述】:
我想在我的适配器的 getview 函数中渲染之前设置 TextView 的高度。 getLineCount 中的结果始终为 0...
public View getView(LayoutInflater inflater, View convertView)
{
textView = (TextView) rowView.findViewById(R.id.text);
textView.setText(strText);
int height_in_pixels = textView.getLineCount() * textView.getLineHeight();// getLineCount is always 0
textView.setHeight(height_in_pixels);
}
我也在想也许可以计算strText 中的字符数,然后根据字符数设置我的高度..
感谢您的帮助
【问题讨论】:
-
TextView 在渲染文本之前不知道实际的行数,因此您遇到了典型的鸡蛋问题。您可以尝试使用 View.INVISIBLE,渲染它,运行您的代码,然后将可见性更改为 View.VISIBLE
-
如何在 getView() 函数中渲染它?
标签: android android-listview textview