日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
解析三大FlexDataGrid背景色調(diào)試方法

本文和大家重點(diǎn)討論一下Flex DataGrid背景顏色調(diào)試,在Flex運(yùn)用中經(jīng)常提到的有關(guān)Flex DataGrid問(wèn)題是如何改變Flex DataGrid單元格(cell),列(column)和行(row)的背景顏色(backgroundcolor)這里對(duì)這3種顏色做一個(gè)總結(jié)。

我們提供的服務(wù)有:成都網(wǎng)站設(shè)計(jì)、做網(wǎng)站、微信公眾號(hào)開(kāi)發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、鄱陽(yáng)ssl等。為上1000+企事業(yè)單位解決了網(wǎng)站和推廣的問(wèn)題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的鄱陽(yáng)網(wǎng)站制作公司

Flex DataGrid背景顏色調(diào)試

在Flex運(yùn)用中經(jīng)常提到的有關(guān)Flex DataGrid問(wèn)題是如何改變Flex DataGrid單元格(cell),列(column)和行(row)的背景顏色(backgroundcolor)這里對(duì)這3種顏色做一個(gè)總結(jié)。

1.設(shè)置行(row)的背景色

主要是通過(guò)對(duì)Flex DataGrid擴(kuò)展,對(duì)protected函數(shù)drawRowBackground()進(jìn)行重寫,具體代碼如下:

 
 
 
  1. overrideprotectedfunctiondrawRowBackground(s:Sprite,rowIndex:int,
  2. y:Number,height:Number,color:uint,dataIndex:int):void  
  3. {  
  4. if(dataIndex>=dataProvider.length){  
  5. super.drawRowBackground(s,rowIndex,y,height,color,dataIndex);  
  6. return;  
  7. }  
  8. if(dataProvider.getItemAt(dataIndex).col3<2000){//setcoloraccordinttodatas  
  9. super.drawRowBackground(s,rowIndex,y,height,0xC0C0C0,dataIndex);  
  10. }else{  
  11. super.drawRowBackground(s,rowIndex,y,height,color,dataIndex);  
  12. }  
  13. }  
  14.  

 這段代碼中根據(jù)Flex DataGrid的數(shù)據(jù)源進(jìn)行判斷來(lái)設(shè)置背景色,但是它有個(gè)缺陷,就是這個(gè)具體的背景色我們無(wú)法自己靈活指定。因此派生出新的CustomRowColorFlex DataGrid,具體代碼如下:

 
 
 
  1. packagecwmlab.controls  
  2. {  
  3. importmx.controls.*;  
  4. importflash.display.Shape;  
  5. importmx.core.FlexShape;  
  6. importflash.display.Graphics;  
  7. importflash.display.Sprite;  
  8. importmx.rpc.events.AbstractEvent;  
  9. importmx.collections.ArrayCollection;  
  10. importflash.events.Event;  
  11. /**  
  12. *Thisisanextendedversionofthebuilt-inFlexFlex DataGrid.  
  13. *Thisextendedversionhasthecorrectoverridelogicinit  
  14. *todrawthebackgroundcolorofthecells,basedonthevalueofthe  
  15. *dataintherow.  
  16. **/  
  17.  
  18. publicclassCustomRowColorFlex DataGridextendsFlex DataGrid  
  19. {  
  20. privatevar_rowColorFunction:Function;  
  21. publicfunctionCustomRowColorFlex DataGrid()  
  22. {  
  23. super();  
  24. }  
  25. /**  
  26. *Auser-definedfunctionthatwillreturnthecorrectcolorofthe  
  27. *row.Usuallybasedontherowdata.  
  28. *  
  29. *expectedfunctionsignature:  
  30. *publicfunctionF(item:Object,defaultColor:uint):uint  
  31. **/  
  32.  
  33. publicfunctionsetrowColorFunction(f:Function):void  
  34. {  
  35. this._rowColorFunction=f;  
  36. }  
  37.  
  38. publicfunctiongetrowColorFunction():Function  
  39. {  
  40. returnthis._rowColorFunction;  
  41. }  
  42.  
  43. /**  
  44. *Drawsarowbackground  
  45. *atthepositionandheightspecifiedusingthe  
  46. *colorspecified.ThisimplementationcreatesaShapeasa  
  47. *childoftheinputSpriteandfillsitwiththeappropriatecolor.  
  48. *ThismethodalsousesthebackgroundAlphastyleproperty  
  49. *settingtodeterminethetransparencyofthebackgroundcolor.  
  50. *  
  51. *@paramsASpritethatwillcontainadisplayobject  
  52. *thatcontainsthegraphicsforthatrow.  
  53. *  
  54. *@paramrowIndexTherow'sindexinthesetofdisplayedrows.The  
  55. *headerdoesnotcount,thetopmostvisiblerowhasarowindexof0.  
  56. *Thisisusedtokeeptrackoftheobjectsusedfordrawing  
  57. *backgroundssoaparticularrowcanre-usethesamedisplayobject  
  58. *eventhoughtheindexoftheitemthatrowisrenderinghaschanged.  
  59. *  
  60. *@paramyThesuggestedypositionforthebackground  
  61. *@paramheightThesuggestedheightfortheindicator  
  62. *@paramcolorThesuggestedcolorfortheindicator  
  63. *  
  64. *@paramdataIndexTheindexoftheitemforthatrowinthe  
  65. *dataprovider.Thiscanbeusedtocolorthe10thitemdifferently  
  66. *forexample.  
  67. */  
  68.  
  69. overrideprotectedfunctiondrawRowBackground(s:Sprite,rowIndex:int,
  70. y:Number,height:Number,color:uint,dataIndex:int):void  
  71. {  
  72. if(this.rowColorFunction!=null){  
  73. if(dataIndex
  74. varitem:Object=this.dataProvider.getItemAt(dataIndex);  
  75. color=this.rowColorFunction.call(this,item,color);  
  76. }  
  77. }  
  78. super.drawRowBackground(s,rowIndex,y,height,color,dataIndex);  
  79. }  
  80. }  
  81. }  
  82.  

 在具體使用過(guò)程中可以這樣調(diào)用:

 
 
 
  1.  
  2. rowColorFunction="setCustomColor"> 
  3. privatefunctionsetCustomColor(item:Object,color:uint):uint  
  4. {  
  5. if(item['col3']>=2000)  
  6. {  
  7. return0xFF0033;  
  8. }  
  9. returncolor;  
  10. }  
  11.  

 #p#2.設(shè)置Flex DataGrid列的背景色

這個(gè)很簡(jiǎn)單,只要設(shè)置Flex DataGridColumn的屬性backgroundColor="0x0000CC"即可。

3.設(shè)置Flex DataGrid單元格(cell)的背景色

這個(gè)主要通過(guò)itemRenderer進(jìn)行設(shè)置,itemRenderer可以是Label,也可以是其他如Flex DataGridItemRenderer。

先看看用Label如何設(shè)置背景色

 
 
 
  1.  
  2.  
  3.  
  4.  
  5. overridepublicfunctionsetdata(value:Object):void  
  6. {  
  7. super.data=value;  
  8. if(value.col1=='Toyota'){  
  9. this.opaqueBackground=0xCC0000;  
  10. }  
  11. }  
  12. ]]> 
  13.  
  14.  
  15.  
  16.  
  17.  

 用Flex DataGridItemRenderer進(jìn)行背景色設(shè)置如下:

 
 
 
  1.  
  2.  
  3.  
  4.  
  5. overridepublicfunctionsetdata(value:Object):void  
  6. {  
  7. super.data=value;  
  8. if(value.col3>=2000){  
  9. this.background=true;  
  10. this.backgroundColor=0x00cc00;  
  11. }  
  12. }  
  13. ]]> 
  14.  
  15.  
  16.  
  17.  
  18.  


當(dāng)前題目:解析三大FlexDataGrid背景色調(diào)試方法
分享地址:http://m.5511xx.com/article/codcpcd.html