如何确定的TextView的高度编程? [英] How to determine the height of TextView programmatically?
问题描述
我已经创建了列表视图的一排的XML。它只有一个TextView的。
I have created an xml for a row of listview. It has just one Textview.
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textColor="@color/white"
android:text="A">
</TextView>
我需要确定这个TextView的高度编程。
如果我code textview.getTextSize()。这才返回文本的大小
I need to determine the height of this textview programmatically. If I code textview.getTextSize(): this just returns the size of text.
编辑:
我要检索的TextView的高度渲染这个屏幕上之前。我的意思是,我想这个充气:
I am want to retrieve the height of the textview prior to rendering this on the screen. I mean, I want to inflate this:
LayoutInflater inflater=LayoutInflater.from(this);
View view=inflater.inflate(R.layout.row, null);
TextView row_textview=((TextView)view);
,然后计算row_textview实例的高度。
and then calculate the height of "row_textview" instance.
推荐答案
你有没有尝试
返回视图的高度。
或者这
像素pssed此TextView的前$ P $的最大高度,或-1,如果
最大高度中的行数设定,而不是使用或
setLines(INT)。
the maximum height of this TextView expressed in pixels, or -1 if the maximum height was set in number of lines instead using or setLines(int).
这篇关于如何确定的TextView的高度编程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!