【问题标题】:Group gets height from original image, not the scaled image组从原始图像获取高度,而不是缩放图像
【发布时间】:2013-06-25 14:54:29
【问题描述】:

在我的应用程序中,我导入了一个 Twitter 时间线。有些推文包含图像,有些则没有。 imqages 的高度也是可变的。我设置了 90% 的宽度以确保图像适合组(使用垂直布局),但无论我做什么,组都会从原始图像获取高度,而不是缩放高度。我尝试设置 variableRowHeight="true",但这似乎没有任何作用。这是一些示例代码:

<s:List id="list" y="0" width="90%" height="954" dataProvider="{tweets}" horizontalCenter="0">
    <s:layout>
        <s:VerticalLayout/>
    </s:layout>
    <s:itemRenderer>
        <fx:Component>
            <s:ItemRenderer>
                <s:Group width="100%">
                <s:Label id="twitlabel" text="{tweetImage.height}"
                             width="100%"
                             styleName="tweetlist"/>
                    <s:Image id="tweetImage" y="{twitlabel.height}" width="90%" horizontalCenter="0" scaleMode="letterbox" smooth="true" source="{data.entities.media[0].media_url}"/>
                </s:Group>
            </s:ItemRenderer>
        </fx:Component>
    </s:itemRenderer>

问题是,如何让组将其高度设置为缩放后的图像高度?

【问题讨论】:

  • 试试这个:&lt;s:VerticalLayout horizontalAlign="justify" useVirtualLayout="false" variableRowHeight="true" /&gt;
  • 感谢您的回复,但这并没有奏效,仍然在该组的项目中出现了巨大的差距。另外,当我将 Image 类设置为 BitmapImage 时,它​​可以工作,但有时图像不显示(但组与图像一样大)。

标签: image actionscript-3 apache-flex flash-builder


【解决方案1】:

首先为您的 Image 设置“完成”事件处理程序并为您的 Group 设置一个 id:

 <s:Group id="tweetImageGroup" width="100%">
 <s:Image id="tweetImage" y="{twitlabel.height}" horizontalCenter="0" scaleMode="letterbox" smooth="true" source="{data.entities.media[0].media_url}" complete="tweetImage_completeHandler(event)"/>

然后设置图片加载完成后的宽度:

protected function tweetImage_completeHandler(event:Event):void{
   tweetImageGroup.height = event.currentTarget.measuredHeight;
}

这可能需要一些调整,但如果我正确理解您的问题应该可以工作。

【讨论】:

    猜你喜欢
    • 2015-09-27
    • 1970-01-01
    • 2011-04-09
    • 2019-09-13
    • 2014-09-06
    • 2013-01-01
    • 1970-01-01
    • 2012-01-24
    • 1970-01-01
    相关资源
    最近更新 更多