android中的textview.getLineCount始终为0 [英] textview.getLineCount always 0 in android
本文介绍了android中的textview.getLineCount始终为0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试动态调整 textview 的大小,但 getlinecount() 方法总是返回 0,即使在 settext() 和 invalidate() 之后也是如此.我正在使用以下代码:
I'm trying to dynamically resize my textview but getlinecount() method always returns me 0 even after settext() and invalidate(). I'm using the following code:
if (convertView == null) {
convertView = lInflater.inflate(R.layout.listview, null);
holder = new ViewHolder();
holder.text2 = (TextView)convertView.findViewById(R.id.TextView02);
convertView.setTag(holder);
} else {
holder = (ViewHolder)convertView.getTag();
}
holder.text2.setText(arr2[position]);
holder.text2.invalidate();
int lineCnt = holder.text2.getLineCount();
holder是一个静态类,如下:
holder is a static class as follows:
static class ViewHolder {
TextView text2;
}
holder 包含非 null text2 且内容集也非 null.
holder contains non null text2 and the content set is also non null.
推荐答案
我知道这个问题已经很老了,但万一有人来这里寻找实际答案:
I know this question is quite old, but in case anyone comes here looking for the actual answer:
holder.text2.setText(arr2[position]);
holder.text2.post(new Runnable() {
@Override
public void run() {
int lineCnt = holder.text2.getLineCount();
// Perform any actions you want based on the line count here.
}
});
这篇关于android中的textview.getLineCount始终为0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文