gpt4 book ai didi

android - android中的textview.getLineCount始终为0

转载 作者:IT老高 更新时间:2023-10-28 21:47:28 25 4
gpt4 key购买 nike

我正在尝试动态调整 textview 的大小,但 getlinecount() 方法总是返回 0,即使在 settext() 和 invalidate() 之后也是如此。我正在使用以下代码:

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是一个静态类,如下:

static class ViewHolder {
TextView text2;
}

holder 包含非 null text2 且内容集也非 null。

最佳答案

我知道这个问题已经很老了,但万一有人来这里寻找实际答案:

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 - android中的textview.getLineCount始终为0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3528790/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com