Spark TextArea 或 RichText 自动调整大小
我对这个主题进行了大量搜索,但似乎我发现的内容要么已经过时,要么似乎不起作用。
在过去的 TextFields 中,您可以将 TextField 设置为特定宽度,将 wordWrap 设置为 true,最终会得到一个根据您添加的文本更改高度的文本字段。
现在我尝试使用 Spark TextArea 或 RichText 来执行此操作。
我尝试了这个 HeightInLines = NAN,但这似乎已经过时了。
我也尝试了这个例程:
var totalHeight:uint = 10;
this.validateNow();
var noOfLines:int = this.mx_internal::getTextField().numLines;
for (var i:int = 0; i < noOfLines; i++)
{
var textLineHeight:int =
this.mx_internal::getTextField().getLineMetrics(i).height;
totalHeight += textLineHeight;
}
this.height = totalHeight;
但是 mx_internal 不在 Spark 组件中。
我正在尝试使用 AS3 而不是 MXML 来做到这一点。如果有人有任何建议或链接可以帮助我使用 AS3 解决这个问题,我将非常感激。
I have done lots of searching on this subject, but it seems what I am finding is either out of date or just does not seem to work.
With TextFields in the past, you could set the TextField to a certain width, set wordWrap to true and you would end up with a textfield that changed height according to the text you added.
Now I am trying to do this with either the Spark TextArea or RichText.
I tried this HeightInLines = NAN, but that seems to be out of date.
I also tried this routine:
var totalHeight:uint = 10;
this.validateNow();
var noOfLines:int = this.mx_internal::getTextField().numLines;
for (var i:int = 0; i < noOfLines; i++)
{
var textLineHeight:int =
this.mx_internal::getTextField().getLineMetrics(i).height;
totalHeight += textLineHeight;
}
this.height = totalHeight;
But the mx_internal is not in the Spark components.
I am trying to do this with AS3, not MXML. If anyone has any suggestions or links that could help me figure this out using AS3, I'd really appreciate it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
整个下午都在为此苦苦挣扎。但如果您设置其宽度并保留其高度未定义,RichEditableText 组件似乎会自动调整大小。
Been struggling with this all afternoon. But it looks like the RichEditableText component will autosize if you set its width and leave its height undefined.
这工作正常:
在评论中找到 此处。您可以在 ActionScript 中使用相同的
updateComplete
事件执行相同的操作。This works fine:
Found in comments here. You can do the same in ActionScript using the same
updateComplete
event.这就是我在 ItemRenderer 内部使用时设置 TextArea 的高度以适合其内容的方法(例如,对于 List 组件):
ItemRenderer 必须设置此属性:
也许 updateComplete 事件不是自动调整大小操作的最佳触发器,但可以工作对我来说很好。
This is how I set the height of a TextArea to fit its content when used inside an ItemRenderer (e.g. for a List component):
ItemRenderer must have this property set:
Maybe the updateComplete event is not the optimal trigger for auto-resize actions but works fine for me.
您可以从 TextArea 的外观中删除滚动条,然后它就会自动调整大小。您可以在此处下载完成的皮肤:http://www.yumasoft.com/node/126
You can remove scrollers from TextArea's skin and it becomes autoresizable. You can download completed skin here: http://www.yumasoft.com/node/126
这是 Spark 文本区域的解决方案(它的工作方式与 mx 文本区域相同):
Here's a solution for spark text areas (it works as mx text areas do):
这似乎对我有用:
This seems to work for me:
一直用同样的头敲击 s:TextArea,然后发现这可以完成工作:
Been doing the same head banging over that s:TextArea, and then found out that this gets the job done :