如何确定TextView中可见的行数? [英] How to determine the number of lines visible in TextView?

查看:597
本文介绍了如何确定TextView中可见的行数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获得多少行显示在的TextView 的可见部分?我使用的文本,它不能完全放在的TextView 在每个屏幕分辨率。

 <?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://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();

编辑:

如果你想唯一可见的行数使用这个答案中提到的方法。

<一个href=\"http://stackoverflow.com/questions/2239356/is-there-a-way-of-retrieving-a-textviews-visible-line-count-or-range\">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?

这篇关于如何确定TextView中可见的行数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆