国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 網(wǎng)站 > WEB開發(fā) > 正文

3.8.使用約束條件為文本創(chuàng)建排版流程(Layout Flows)

2024-04-27 13:51:48
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
3.8.1 問(wèn)題
你要為多段文字創(chuàng)建一個(gè)排版流程(layout flow)。
3.8.2 解決辦法
創(chuàng)建并添加一個(gè)ConstraintColumn 和ConstraintRow 對(duì)象到Canvas 組件,然后使用它們?yōu)樽咏M件設(shè)置約束條件。
3.8.3 討論
所有支持約束條件的容器都具有兩個(gè)數(shù)組來(lái)存儲(chǔ)加到該Canvas 的行和列的軌跡。只需為各自數(shù)組添加現(xiàn)成的約束條件即可保證所有的子組件可以存取約束條件到它的屬性。本節(jié)的例子就是用約束條件來(lái)控制排版流程(layout flow)。首先,創(chuàng)建多個(gè)ConstraintColumn 和ConstraintRow 對(duì)象,然后將這些對(duì)象添加到Canvas 的constraintRows 和constraintColumns 屬性。使用setStyle 方法動(dòng)態(tài)的將約束條件設(shè)置到現(xiàn)成的UIComponent對(duì)象來(lái)約束之。這個(gè)例子使用text.setStyle("left", constraintColumn.id+":10"); 從ConstraintColumn 對(duì)象的數(shù)組中動(dòng)態(tài)地存取約束條件,或者使用下面這樣稍微復(fù)雜的句式以保證訪問(wèn)到正確的列。如:
+展開
-ActionScript
child.setStyle("left",(constraintColumns[i-
(constraintColumns.length/2)-2] as ConstraintColumn).id+":10");


在接下來(lái)的清單里,生成ConstraintColumn 對(duì)象并且基于這些對(duì)象來(lái)設(shè)置新子組件的樣式屬性。當(dāng)添加新的行時(shí),相關(guān)的子組件會(huì)使用新的行重新設(shè)置樣式來(lái)改變自己的位置,并且所有未使用過(guò)的ConstraintColumn 對(duì)象會(huì)從容器中移除,constraintColumns 即是這些數(shù)組的縮寫。
+展開
-XML
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxmlwidth="1000"
height="800">

<mx:Script>
<![CDATA[
import mx.core.UIComponent;
import mx.controls.TextArea;
import mx.containers.utilityClasses.ConstraintColumn;
[Bindable]
public var txt:String = "Cort¨¢zar is highly regarded
as a master of short stories of a fantastic bent,
with the collections Bestiario (1951)" +
" and Final de Juego (1956) containing many of his
best examples in the genre, including the remarkable
/"Continuidad de los Parques/"" +
" and /"Axolotl./"";
private function addText(event:Event):void
{
var text:TextArea = new TextArea();
addChild(text);
text.text = txt;
var constraintColumn:ConstraintColumn =
new ConstraintColumn();
constraintColumn.id =
"column"+numChildren.toString();
constraintColumns.push(constraintColumn);
if(constraintColumns.length > 1)
{
for each(var col:ConstraintColumn in
constraintColumns){
col.width = (width / (numChildren-2));
}
}c
onstraintColumn.width = (width / (numChildren-2));
text.setStyle("top""row:30");
text.setStyle("bottom""row:30");
text.setStyle("left", constraintColumn.id+":10");
text.setStyle("right", constraintColumn.id+":10");
}
private function addRow(event:Event):void
{
var constraintRow:ConstraintRow =
new ConstraintRow();
constraintRows.push(constraintRow);
constraintRow.id = "row"+constraintRows.length;
for each(var row:ConstraintRow in constraintRows){
row.height = (height / (constraintRows.length-1));
}
var i:int = Math.round(numChildren - (numChildren-
2)/constraintRows.length);
while(i < numChildren){
var child:UIComponent = (getChildAt(i) as
UIComponent);
child.setStyle("top",
"row"+constraintRows.length+":30");
child.setStyle("bottom",
"row"+constraintRows.length+":30");
child.setStyle("left", (constraintColumns[i-
(constraintColumns.length/2)-2] as
ConstraintColumn).id+":10");
child.setStyle("right", (constraintColumns[i-
(constraintColumns.length/2)-2] as
ConstraintColumn).id+":10");
i++;
}c
onstraintColumns.length = constraintColumns.length
/ constraintRows.length;
}

]]>
</mx:Script>
<mx:constraintRows>
<mx:ConstraintRow id="rowheight="100%"/>
</mx:constraintRows>
<mx:Button click="addText(event)label="add text"/>
<mx:Button click="addRow(event)label="add rowx="150"/>
</mx:Canvas>
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 汉沽区| 鄂尔多斯市| 淄博市| 新宾| 郸城县| 泽普县| 舟山市| 襄城县| 揭西县| 株洲市| 聊城市| 靖江市| 布尔津县| 内江市| 儋州市| 资溪县| 伊宁市| 杨浦区| 松原市| 于都县| 临湘市| 武宁县| 绥芬河市| 封开县| 博白县| 佛山市| 密山市| 历史| 天水市| 云和县| 简阳市| 鹿邑县| 永昌县| 辽宁省| 贵阳市| 灵丘县| 呼和浩特市| 武隆县| 黔西县| 南安市| 凤台县|