上一个教程中,虽然播放列表的框架和迅雷一样了,但是字体大小、文字居中还没有解决。如果是刚学duilib,搞定这个可不容易,因为在有了入门教程的指导后,很容易就想到去看【属性列表.XML】,但是当你试了一圈之后,发现font、itemfont、align、itemalign等等,都没有效果!

  这个时候就只有去看duilib内部的代码了,和上个教程一样,虽然小伙伴们花一个晚上或者几个晚上就能搞出来,但一样没什么含金量,纯体力活,所以Alberl在这里告知一下小伙伴,省得重复掉坑。

  虽然CTreeViewUI继承于CListUI,但是其font、itemfont、align、itemalign等属性并不生效,因为TreeView是由TreeNode组成,但写这个类的大神并没有将TreeView的item属性应用到TreeNode中,所以大部分属性需要到TreeNode里设置,而CTreeNodeUI 继承于CListContainerElementUI,是不是和List同一个结构呢~ 但由于TreeView比较复杂,而完善TreeView对大神们也是体力活,没有含金量,最重要的是,天朝的开源状况已经让大神们心都凉了,Alberl在写这些教程的时候,看到有些回复和聊天记录也有些心凉了,刚入门的码农不了解开源状况就不计较了,但是有些工作两三年甚至更久的,好吧,也不计较了。。。

  嗯,TreeView不完善的原因也说明了,那么在这个不完善的基础上,可用性还是很不错的,至少一下子就搞出了迅雷那样的播放列表,只是细节问题需要花点时间而已,而Alberl已经花了这个时间了,就为后面的小伙伴们节省下时间吧。

  CTreeNodeUI 主要由CCheckBoxUI、CLabelUI、COptionUI等控件组成,要调整文字的话,就要设置COptionUI(注意:不是CLabelUI)的属性了,而此COptionUI的属性通过设置itemattr生效,<TreeNode itemattr="align=&quot;center&quot; font=&quot;4&quot;" />即代表TreeNode的文字居中,且字体序号是4,这样就可以看到字体加粗了,不过可以发现文字只是水平居中,并没有垂直居中,这也是duilib的一个bug,后面教程将会给出解决方案。

  如果要设置展开与折叠图标,就要设置folderattr属性,这个在duilib的TestApp1里已经有例子了,而本节最后也会给出完整代码,因此就不介绍了,不过需要说明的是,并不是每个节点都需要显示图标,虽然不设置folderattr属性就不会显示图标,但是你会发现,当我们双击节点的时候,会显示一个色块,也就是在图标的位置,这是因为虽然没显示图标,但其实CCheckBoxUI还是显示了的,这时我们需要隐藏这个CCheckBoxUI,怎么办呢?  你会发现<TreeNode folderattr ="visible=&quot;false&quot;" />是无法解决这个问题的,因为在读取了XML的属性之后,Treeview还自行设置了visible属性,这也算是一个bug,但是在不改代码的前提下,我们也是有解决方案的,在Treeview里加上visiblefolderbtn属性,<Treeview  visiblefolderbtn="false" />就隐藏了折叠按钮,这时再双击,就不会出现色块了。

  但是呢,这样就让所有的折叠按钮都隐藏了,而我们又需要显示某些节点的折叠按钮,这个时候我们加上<TreeNode folderattr ="visible=&quot;true&quot;" />,会发现也是无效的,嗯,这就是TreeView的bug,看来不能用visiblefolderbtn属性,Alberl的解决方法是,将折叠按钮的宽度设置为0,即<TreeNode folderattr ="width=&quot;0&quot; float=&quot;true&quot;" />,这样就可以完美隐藏折叠按钮啦。  由于我们有很多个节点都需要同样的设置,那咱们来设置一下Default属性呗~O(∩_∩)O~

  不好意思,Treeview的folderattr 等属性好像在Default设置不了,因为Default属性是用value=""来设置了,这就决定了里面最多能套一层双引号,如果我们这样设置

<Default name="TreeView" value=" folderattr =&quot;width=&quot;0&quot; float=&quot;true&quot;&quot; ">,那么duilib并不能解析出来,因为他的逻辑是于下一个双引号匹配,虽然改逻辑可以解决这个问题,但是不建议这样做,我们可以用{}等符号代替,既方便又安全。但是Alberl只是个入门者而已,必然不建议去改代码,因此只能在每个节点都加上folderattr 属性啦。

  到这里,我们就实现了和迅雷一样的播放列表啦,包括字体大小,文字居中等等。

  

  完整XML如下(这里只需要将XML替换到上一个教程中即可,因此不再给出代码下载):

        <TreeView name="treePlaylist" childpadding="4" multipleitem="true" inset="4,0,3,0" bordersize="1" bordercolor="#FF2B2B2B" itemtextcolor="#FFC8C6CB" itemhottextcolor="#FFC8C6CB" selitemtextcolor="#FFC8C6CB" itemhotbkcolor="#FF1B1B1B" itemselectedbkcolor="#FF151C2C" vscrollbar="true" hscrollbar="true" >
<TreeNode name="nodePlaylist" text="播放列表" height="33" bkimage="treeview_header.png" itemattr="valign=&quot;vcenter&quot; font=&quot;1&quot; textpadding=&quot;12,0,0,0&quot;" folderattr="width=&quot;0&quot; float=&quot;true&quot;">
<TreeNode height="34" folderattr="width=&quot;0&quot; float=&quot;true&quot;">
<Combo name="comboPlaylist" float="true" pos="12,7,0,0" valign="vcenter" width="70" height="20" dropboxsize="63,63" itemfont="0" itemtextcolor="#FFC8C6CB" itemselectedtextcolor="#FFC8C6CB" itemhottextcolor="#FFC8C6CB" itembkcolor="#FF2E2E2E" itemselectedbkcolor="#FF2E2E2E" itemhotbkcolor="#FF191919" normalimage="file='combo_right.png' source='0,0,20,20' dest='27,0,47,20' " hotimage="file='combo_right.png' source='21,0,41,20' dest='27,0,47,20' ">
<ListLabelElement text="全部" font="0"/>
<ListLabelElement text="在线" font="0"/>
<ListLabelElement text="本地" font="0" selected="true" />
</Combo>
<VerticalLayout width="65">
<Button name="btnPlayMode" tooltip="播放模式" float="true" pos="0,8,0,0" width="18" height="18" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;btn_play_mode.png&apos; source=&apos;0,0,18,18&apos;" hotimage="file=&apos;btn_play_mode.png&apos; source=&apos;19,0,37,18&apos;" pushedimage="file=&apos;btn_play_mode.png&apos; source=&apos;38,0,56,18&apos;" />
<Button name="btnAdd" float="true" pos="21,8,0,0" width="18" height="18" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;btn_add.png&apos; source=&apos;0,0,18,18&apos;" hotimage="file=&apos;btn_add.png&apos; source=&apos;19,0,37,18&apos;" pushedimage="file=&apos;btn_add.png&apos; source=&apos;38,0,56,18&apos;" />
<Button name="btnDelete" float="true" pos="42,8,0,0" width="18" height="18" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file=&apos;btn_delete.png&apos; source=&apos;0,0,18,18&apos;" hotimage="file=&apos;btn_delete.png&apos; source=&apos;19,0,37,18&apos;" pushedimage="file=&apos;btn_delete.png&apos; source=&apos;38,0,56,18&apos;" />
</VerticalLayout>
</TreeNode>
<TreeNode text="迅雷下载" inset="-8,0,0,0" height="22" itemattr="valign=&quot;vcenter&quot; font=&quot;0&quot; textpadding=&quot;4,0,0,0&quot;" folderattr="padding=&quot;0,5,0,0&quot; width=&quot;12&quot; height=&quot;12&quot; selectedimage=&quot;file='treeview_expand.png' source='0,0,12,12' &quot; normalimage=&quot;file='treeview_expand.png' source='13,0,25,12' &quot;">
<TreeNode text="下载1" height="22" inset="7,0,0,0" itemattr="valign=&quot;vcenter&quot; font=&quot;4&quot;" folderattr="width=&quot;0&quot; float=&quot;true&quot;"/>
<TreeNode text="下载2" height="22" inset="7,0,0,0" itemattr="valign=&quot;vcenter&quot; font=&quot;4&quot;" folderattr="width=&quot;0&quot; float=&quot;true&quot;"/>
</TreeNode>
</TreeNode>
<TreeNode text="在线媒体" height="33" bkimage="treeview_header.png" itemattr="valign=&quot;vcenter&quot; font=&quot;1&quot; textpadding=&quot;12,0,0,0&quot;" folderattr="width=&quot;0&quot; float=&quot;true&quot;">
<TreeNode text="今日热播" inset="-8,0,0,0" height="22" itemattr="valign=&quot;vcenter&quot; font=&quot;0&quot; textpadding=&quot;4,0,0,0&quot;" folderattr="padding=&quot;0,5,0,0&quot; width=&quot;12&quot; height=&quot;12&quot; selectedimage=&quot;file='treeview_expand.png' source='0,0,12,12' &quot; normalimage=&quot;file='treeview_expand.png' source='13,0,25,12' &quot;">
<TreeNode text="八公" height="22" inset="7,0,0,0" itemattr="valign=&quot;vcenter&quot; font=&quot;4&quot;" folderattr="width=&quot;0&quot; float=&quot;true&quot;"/>
<TreeNode text="HACHI" height="22" inset="7,0,0,0" itemattr="valign=&quot;vcenter&quot; font=&quot;4&quot;" folderattr="width=&quot;0&quot; float=&quot;true&quot;"/>
</TreeNode>
<TreeNode text="热点新闻" inset="-8,0,0,0" height="22" itemattr="valign=&quot;vcenter&quot; font=&quot;0&quot; textpadding=&quot;4,0,0,0&quot;" folderattr="padding=&quot;0,5,0,0&quot; width=&quot;12&quot; height=&quot;12&quot; selectedimage=&quot;file='treeview_expand.png' source='0,0,12,12' &quot; normalimage=&quot;file='treeview_expand.png' source='13,0,25,12' &quot;">
<TreeNode text="八公" height="22" inset="7,0,0,0" itemattr="valign=&quot;vcenter&quot; font=&quot;4&quot;" folderattr="width=&quot;0&quot; float=&quot;true&quot;"/>
<TreeNode text="HACHI" height="22" inset="7,0,0,0" itemattr="valign=&quot;vcenter&quot; font=&quot;4&quot;" folderattr="width=&quot;0&quot; float=&quot;true&quot;"/>
</TreeNode>
</TreeNode>
<TreeNode text="娱乐中心" height="33" bkimage="treeview_header.png" itemattr="valign=&quot;vcenter&quot; font=&quot;1&quot; textpadding=&quot;12,0,0,0&quot;" folderattr="width=&quot;0&quot; float=&quot;true&quot;">
<TreeNode text="短视频广场" inset="-8,0,0,0" height="22" itemattr="valign=&quot;vcenter&quot; font=&quot;0&quot; textpadding=&quot;4,0,0,0&quot;" folderattr="padding=&quot;0,5,0,0&quot; width=&quot;12&quot; height=&quot;12&quot; selectedimage=&quot;file='treeview_expand.png' source='0,0,12,12' &quot; normalimage=&quot;file='treeview_expand.png' source='13,0,25,12' &quot;">
<TreeNode text="热门视频" height="22" inset="7,0,0,0" itemattr="valign=&quot;vcenter&quot; font=&quot;4&quot;" folderattr="width=&quot;0&quot; float=&quot;true&quot;"/>
<TreeNode text="美女视频" height="22" inset="7,0,0,0" itemattr="valign=&quot;vcenter&quot; font=&quot;4&quot;" folderattr="width=&quot;0&quot; float=&quot;true&quot;"/>
</TreeNode>
<TreeNode text="直播频道" height="22" inset="8,0,0,0" itemattr="valign=&quot;vcenter&quot; font=&quot;0&quot;" folderattr="width=&quot;0&quot; float=&quot;true&quot;"/>
</TreeNode>
</TreeView>

  不过亲们可以发现如果你们自行编译的话,文字不会垂直居中,并且发现Alberl用了valign属性,嗯,这个将在下一个教程介绍~O(∩_∩)O~

duilib进阶教程 -- TreeView控件的不足 (7)的更多相关文章

  1. duilib进阶教程 -- TreeView控件(6)

    代码下载:http://download.csdn.net/detail/qq316293804/6483905 上一个教程中,界面已经和迅雷一模一样啦,大小和位置一个像素都不差哟,亏得Alberl调 ...

  2. duilib进阶教程 -- TreeView控件的bug (9)

    一.不自动调整子控件的宽度(TreeView宽度小于260时) 相信亲们用同样的代码,显示效果肯定和Alberl不一样吧~O(∩_∩)O~ 嘿嘿,仔细对比下,看看你们的列表头背景图片是下面这样的么? ...

  3. duilib进阶教程 -- Container控件的bug (14)

    在<duilib进阶教程 -- TreeView控件的bug (9)>里,Alberl发现了两个bug,并解决了其中一个,现在教程已经接近尾声啦,所以Alberl就解决了另外一个bug. ...

  4. duilib进阶教程 -- 各种控件的响应 (10)

    到上一个教程为止,界面显示的代码就都介绍完啦,现在开始介绍控件的响应,其实在<2013 duilib入门简明教程 -- 事件处理和消息响应 (17)>里已经列出了duilib自己定义的所有 ...

  5. duilib进阶教程 -- Label控件的bug (8)

    上个教程说到了TreeView的文字不能垂直居中的问题,而我们用LabelUI其实是可以垂直居中的,为什么不说是TreeView的bug,而说是Label控件的bug呢?因为影响TreeView垂直居 ...

  6. duilib进阶教程 -- Container控件 (3)

    前面两个教程的目的是教大家与MFC结合,那么从这篇起,将不再使用MFC,而使用纯win32项目,本文的所有知识已经在<duilib入门教程>里面讲过了,因此基础知识不再赘述. 代码下载:h ...

  7. 【ASP.NET 进阶】TreeView控件学习

    这几天上班没事做,也不好打酱油,学点没接触过的新东西吧,基本了解了下TreeView控件. TreeView 控件用于在树结构中显示分层数据,例如目录或文件目录等. 下面看代码吧: 1.效果图 2.静 ...

  8. 百度地图Api进阶教程-默认控件和自定义控件2.html

    <!DOCTYPE html> <html> <head> <meta name="viewport" content="ini ...

  9. duilib进阶教程 -- 总结 (17)

    整个教程的代码下载:http://download.csdn.net/detail/qq316293804/6502207 (由于duilib进阶教程主要介绍界面,所以这个教程只给出界面相关的代码,完 ...

随机推荐

  1. 早期(编译器)优化--Java语法糖的味道

    1.泛型与类型擦除 泛型的本质是参数化类型的应用,也就是说所操作的数据类型被指定为一个参数.这种参数类型可以用在类.接口和方法的创建中,分别称为泛型类.泛型接口和泛型方法.在泛型没有出现之前,只能通过 ...

  2. 10个提升MySQL性能的小技巧

    从工作量分析到索引的三条规则,这些专家见解肯定会让您的MySQL服务器尖叫. 在所有的关系数据库中,MySQL已经被证明了完全是一头野兽,只要通知停止运行就绝对不会让你多等一秒钟,使你的应用置于困境之 ...

  3. Android 热修复方案Tinker(一) Application改造

    基于Tinker V1.7.5 Android 热修复方案Tinker(一) Application改造    Android 热修复方案Tinker(二) 补丁加载流程    Android 热修复 ...

  4. js 获取浏览器/网页宽度高度整理

    网页宽度.高度: 网页可见区域宽: document.body.clientWidth 网页可见区域高: document.body.clientHeight 网页可见区域宽: document.bo ...

  5. DHCP服务原理与搭建(Linux系统+路由器,二选一方案)

    大家都知道上网的最基本前提是要在终端上设置IP.子网掩码.网关.DNS等地址信息,在家里或者在办公室很多时候打开电脑后发现就可以上网,并没有手动设置IP.掩码.DNS地址也能上网,这是什么原因呢?其实 ...

  6. Apache Kafka学习 (二) - 多代理(broker)集群

    1. 配置server.properties > cp config/server.properties config/server-1.properties> cp config/ser ...

  7. .net跨平台分析软件

    https://marketplace.visualstudio.com/items?itemName=ConnieYau.NETPortabilityAnalyzer

  8. Scala字符串插值

    Scala提供了三种字符串插值方式:s,f和raw.1. s字符串插值器简单的说就是解析字符串变量. val name = "Tom" println(s"His nam ...

  9. EOF多行写入文件防止变量替换

    问题描述 对多个变量及多行输出到文件,存在变量自动替换,当使用cat<<EOF不想对内容进行变量替换.命令替换.参数展开等 问题解决 转义特殊字符如 $ `等 一.对 $·\ 进行转义 c ...

  10. 【SqlServer】SqlServer中的更新锁(UPDLOCK)

    UPDLOCK.UPDLOCK 的优点是允许您读取数据(不阻塞其它事务)并在以后更新数据,同时确保自从上次读取数据后数据没有被更改.当我们用UPDLOCK来读取记录时可以对取到的记录加上更新锁,从而加 ...