【发布时间】:2011-06-25 18:26:16
【问题描述】:
我有一个 Flex 自定义 BorderContainer 组件,其中包含文本。如果我要将它添加到面板内的主应用程序中,则 BorderContainer 会超出面板的宽度范围,因为文本是设定的大小。我将其所有组件都以百分比表示,以便在缩小时重新调整大小,但是包含复选框和标签(很多带有文本的东西)的部分会因为字体大小没有改变而混乱。
我非常肯定我正在寻找的结果可以通过嵌入字体来完成,尽管我无法从网上提出解决方案。我正在尝试使用 CSS 样式来做到这一点,因为我会将它用于许多不同的组件(我不只是想直接在 flex 代码中更改它)。
编辑解决方案:
我尝试使用www0z0k 建议的比率,但是当它快速调整大小或小屏幕时会导致一些严重问题(组件不会正确调整大小,因为它乘以比率。最终似乎对我有用并且没有引起任何问题的是我运行了代码并找到了容器的width (1152) 和 height (842)。
然后我创建了一个 widthX = 1152 和 heightY = 842 的 const 变量,并在 onResize() 函数中对调整大小进行了编码,如下所示:
(其中bottomGroup 是我要调整大小的borderContainer 的id)
bottomGroup.scaleX = width / widthX;;
bottomGroup.scaleY = height / heightY;
结束编辑
到目前为止,我在<fx:Style> 中找到了一些嵌入字体的示例,并试图删除对 fontSize 的任何声明,但这似乎不起作用。
<fx:Style>
@namespace s "library://ns.adobe.com/flex/spark";
@font-face {
src: url("fonts\Arial.ttf");
fontFamily: myFontFamily;
color: black;
fontStyle: normal;
fontWeight: normal;
advancedAntiAliasing: false;
}
s|BorderContainer {
fontFamily: myFontFamily;
}
</fx:Style>
如果有人有任何建议或知道我哪里出错了,我们将不胜感激。谢谢。
编辑:显示我的问题的示例应用程序。
CustomContainer.mxml
<?xml version="1.0" encoding="utf-8"?>
<s:BorderContainer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" width="100%" height="100%">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:HGroup>
<s:Label text="This is a label" />
<s:Label text="Here is another which add up to take up quite a bit of horizontal space" />
<s:Label text="Here is another which add up to take up quite a bit of horizontal space" />
<s:Label text="Here is another which add up to take up quite a bit of horizontal space" />
</s:HGroup>
Main.mxml
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:local="*"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<fx:Style>
@namespace s "library://ns.adobe.com/flex/spark";
@font-face {
src: url("fonts\Arial.ttf");
fontFamily: myFontFamily;
color: black;
fontStyle: normal;
fontWeight: normal;
advancedAntiAliasing: false;
}
s|BorderContainer {
fontFamily: myFontFamily;
}
</fx:Style>
<s:Panel title="BorderContainer Component Example"
width="75%" height="75%"
horizontalCenter="0" verticalCenter="0">
<local:container>
</local:container>
</s:Panel>
我希望能够重新调整字体大小以适应面板。我无法提供我正在处理的实际代码,但这个例子希望能传达这个想法。
【问题讨论】:
-
有什么问题?您能否发布更多代码,特别是您提到的面板和 BorderContainer 的代码?
-
嗯,当然,等等。问题是您是否能够让文本重新调整大小以适应给定区域而不超出其边界
-
发布了新代码,这只是一些快速的东西,但希望它能澄清问题。我希望文本重新调整大小以适合面板,而不是继续超出面板宽度。
-
假设您的应用程序以等于 minWidth 值的宽度开始,您的 BorderContainer 超出面板宽度的原因是应用程序和 BC 都有主宽度,但您设置了面板拥有应用程序宽度的 75%。
-
对不起,我没有注意到我放的代码,但我实际上拥有的是自定义容器有 width="100%" 和 height="100%" 并且它仍然是同样的问题
标签: css apache-flex fonts flex4 resize