我有一个多行textview。它的高度取决于其他视图。我想从textview获取不可见的文本。
我已尝试使用此代码来获取不可见的文本,但它只显示空文本,但textview具有不可见的文本
final TextView shortDescription = (TextView) v.findViewById(R.id.short_description);
shortDescription.setText(data.getDescription());
ViewTreeObserver vto = shortDescription.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
String text = list.get(position).getDescription();
Layout layout = shortDescription.getLayout();
int end = layout.getLineEnd(layout.getLineCount() - 1);
String invisibletext = text.substring(end, text.length());
Log.e("TAG", "Invisible text:" + invisibletext);
}
});