学习分享 lex tree diffrient row height(tree的行高调节)

Creating a Flex Tree with variable height rows can be mysteriously difficult if you are new to Flex item renderers.  This cookbook will give you the step by step instructions to creating a Tree control with variable height renderers.

First you will need to define your tree component:

 1 <mx:Tree itemRenderer="{new ClassFactory(CustomTreeItemRenderer)}"
 2     labelField="@name"
 3     showRoot="false"
 4     variableRowHeight="true"
 5     width="200"
 6     height="350">
 7   <mx:XMLListCollection id="Characters">
 8    <mx:XMLList>
 9     <movie>
10      <main name="Leon" height="25">
11       <sub name="Mathilda" height="50"/>
12       <sub name="Tony" height="75"/>
13      </main>
14      <main name="Stansfield" height="50">
15       <sub name="Benny" height="100"/>
16      </main>
17     </movie>
18    </mx:XMLList>
19   </mx:XMLListCollection>
20  </mx:Tree>

Notice that the tree control has the attribute "variableRowHeight" set to true.  This is very important since it will allow all of the rows to be a different height.  We also set our data provider to have names which will be used as our renderer‘s label and heights which will be used to resize each renderer.

The next most important attribute here is the "itemRenderer" which is defined as new ClassFactory(CustomTreeItemRenderer).  This means that we will be using a component called the CustomTreeItemRenderer as our itemRenderer.

Now, we must create the CustomTreeItemRenderer.  This will extend the TreeItemRenderer and will override two methods:

  • measure
  • updateDisplayList

The measure method simply measures all of the components within the renderer and sets their heights and widths.  Below we can see what our code must do:

override protected function measure():void{
    super.measure();
    //Check to make sure the data is initialized
    if(data && [email protected] > 0){
        this.measuredHeight = [email protected];
    }
}

Above, you can see that the code is simply setting the measuredHeight of our renderer to the height that was defined in our tree‘s data provider above.  The @ sign in from of the height attribute is used since we are extracting data from our XML based dataprovider rather than an Object based dataprovider.

Now, that the height is set, we need to override the updateDisplayList method so that we can correctly layout out newly resized component.

override protected function updateDisplayList(unscaledWidth:Number,
                                                      unscaledHeight:Number):void{
    super.updateDisplayList(unscaledWidth, unscaledHeight);
    //Check to make sure the data is initialized
    if(data && [email protected] > 0){
        //put the label at the correct y coordinate based on the height
        label.y = ([email protected] / 2) - (label.measuredHeight /2);
    }
}

We can see in the code above, that we are setting the label‘s y coordinate based on the new height of the renderer.  This is necessary in order to vertically align our label within the new larger renderer.

That‘s it.  We now have Flex Tree with variable height rows!

See the sample below which will allow you to download the source by right clicking:

时间: 2024-10-29 19:07:39

学习分享 lex tree diffrient row height(tree的行高调节)的相关文章

Convert Sorted Array to Binary Search Tree With Minimal Height

Given a sorted (increasing order) array, Convert it to create a binary tree with minimal height. Example Given [1,2,3,4,5,6,7], return 4 / 2 6 / \ / 1 3 5 7 分析:这是一道非常明显的递归题.取array的中间数作为树的root,array 左边部分是左子树部分,array右边部分是右子树部分. 1 /** 2 * Definition of

[lintcode easy]Convert Sorted Array to Binary Search Tree With Minimal Height

Given a sorted (increasing order) array, Convert it to create a binary tree with minimal height. Example Given [1,2,3,4,5,6,7], return 4 / 2 6 / \ / 1 3 5 7 Note There may exist multiple valid solutions, return any of them. ////////////////////// 二叉查

623. Add One Row to Tree

Problem statement Given the root of a binary tree, then value v and depth d, you need to add a row of nodes with value v at the given depth d. The root node is at depth 1. The adding rule is: given a positive integer depth d, for each NOT null tree n

Leetcode 623. Add One Row to Tree

Given the root of a binary tree, then value v and depth d, you need to add a row of nodes with value v at the given depth d. The root node is at depth 1. The adding rule is: given a positive integer depth d, for each NOT null tree nodes N in depth d-

【Lintcode]177.Convert Sorted Array to Binary Search Tree With Minimal Height

题目: Given a sorted (increasing order) array, Convert it to create a binary tree with minimal height. Example Given [1,2,3,4,5,6,7], return 4 / 2 6 / \ / 1 3 5 7 题解: Solution 1 () class Solution { public: TreeNode *sortedArrayToBST(vector<int> &A

623. Add One Row to Tree 将一行添加到树中

Given the root of a binary tree, then value v and depth d, you need to add a row of nodes with value v at the given depth d. The root node is at depth 1. The adding rule is: given a positive integer depth d, for each NOT null tree nodes N in depth d-

[Swift]LeetCode623. 在二叉树中增加一行 | Add One Row to Tree

Given the root of a binary tree, then value v and depth d, you need to add a row of nodes with value v at the given depth d. The root node is at depth 1. The adding rule is: given a positive integer depth d, for each NOT null tree nodes N in depth d-

salesforce 零基础学习(七十)使用jquery tree实现树形结构模式

项目中UI需要用到树形结构显示内容,后来尽管不需要做了,不过还是自己做着玩玩,mark一下,免得以后项目中用到. 实现树形结构在此使用的是jquery的dynatree.js.关于dynatree的使用可以参考:http://wwwendt.de/tech/dynatree/doc/dynatree-doc.html#h4.2 对于树形结构,这里不做太多介绍,树一般需要一个根节点,根节点下面可以有很多子节点或者叶子节点,子结点也可以包含叶子结点或者子节点.我们在设计表结构的时候可以考虑自连接操作

Swagger框架学习分享

Swagger框架学习分享 转至元数据结尾 Created and last modified by 刘新宇 大约1分钟以前 转至元数据起始 一.背景介绍 1.1.项目简介 1.2.code repository 1.3.演示项目 二.开发准备 2.1.环境准备 2.2.项目搭建 2.2.1.jar仓库 2.2.2.相关依赖 2.2.3.编写配置文件 2.2.4.与swagger-ui集成 2.6.5.Controller配置 2.2.6.启动中间件 2.2.7.需求定制 三.学习感想 一.背景