本文介绍了获取一个TextView的措施,高度不添加到视图层次结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到下面的要求


  1. 我需要用树叶寄予左右,从屏幕顶部向底部构建一棵树。我不能把树叶在ListView,因为拖的叶子会在相同的偏移。

  1. I need to build a tree with leaves placed left and right, from the screen top to the bottom. I can not put the leaves in a ListView because tow leaves will be in same offset.

我不知道这个项目的高度。

I don't know the height of the items.

我需要$ P $对计算的动态内容的高度,如具有不同长度的字符串

I need to pre-calculate the height of dynamic content, such as strings with different lengths.

问:

如何pre-计算将放在描述为一个TextView小部件有刺的高度如下:

How can i pre-calculate the height of a sting which will be put in a TextView widget described as follows:

   <TextView
    android:id="@+id/note_content"
    android:layout_width="40sp"
    android:layout_height="wrap_content"
    android:maxLines="5" />

推荐答案

创建的TextView,设置的LayoutParams,集文字,调用它的测量方法和读取测量值。顺便说一句,你可以测量文本,而不是TextView的(见)。

Create textView, set LayoutParams, set text, call it's measure method and read measured values. BTW you can measure text, not textView (see StaticLayout).

我想你最好创建自定义布局,你可以实现你所有的叶子measument的算法。 自定义布局很容易)

I think you better create your custom layout where you can implement all your "leaves measument" algorithms. Check this lesson. Custom layout is very easy )

这篇关于获取一个TextView的措施,高度不添加到视图层次结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 03:51