如何获得多少行显示在的TextView
的可见部分?我使用的文本,它不能完全放在的TextView
在每个屏幕分辨率。
<?XML版本=1.0编码=UTF-8&GT?;< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android机器人:layout_width =match_parent机器人:layout_height =match_parent机器人:方向=垂直><的TextView 机器人:ID =@ + ID / logs_text 机器人:layout_width =match_parent 机器人:layout_height =match_parent/>< / LinearLayout中>字符串s =非常大的文本TextView的logText =(TextView中)view.findViewById(R.id.logs_text);logText.setText(多个);
解决方案
android.text.Layout 包含此信息和更多的
最终诠释lineCount = textView.getLayout()getLineCount();
编辑:
如果你想唯一可见的行数使用这个答案中提到的方法。
Is有检索一个TextView的可视行数或范围的一种方式?
how to get how many lines are displayed in visible part of TextView
? I use text, which not fully placed in TextView
on every screen resolution.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/logs_text"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
String s = "very big text"
TextView logText = (TextView) view.findViewById(R.id.logs_text);
logText.setText(s);
解决方案
android.text.Layout contains this information and more
final int lineCount = textView.getLayout().getLineCount();
Edit:
If you want only visible line count use the approach mentioned in this answer.
Is there a way of retrieving a TextView's visible line count or range?