自定义渲染器和主题的问题
[ENGLISH]Problem With custon List ItemRenderer and theme
[原文]http://forum.starling-framework.org/topic/problem-with-custom-list-itemrenderer-and-theme
开始
要做自定义列表项渲染主题,
比如,用MetalWorksMobile主题,TileList例子
现在,我想自定义背景,和自定义标签
override protected function initialize():void
{
const collection:ListCollection = new ListCollection(
[
{ label2: "Videos", texture: this._iconAtlas.getTexture("projector"), event: SHOW_VIEW_VIDEO},
{ label2: "Search", texture: this._iconAtlas.getTexture("search"), event: SHOW_VIEW_SEARCH },
{ label2: "Options", texture: this._iconAtlas.getTexture("setting"), event: SHOW_VIEW_OPTIONS },
{ label2: "Help", texture: this._iconAtlas.getTexture("help"), event: SHOW_VIEW_HELP },
{ label2: "About very long", texture: this._iconAtlas.getTexture("about"), event: SHOW_VIEW_ABOUT },
]);
const listLayout:TiledRowsLayout = new TiledRowsLayout();
listLayout.paging = TiledRowsLayout.PAGING_HORIZONTAL;
listLayout.useSquareTiles = false;
listLayout.tileHorizontalAlign = TiledRowsLayout.TILE_HORIZONTAL_ALIGN_CENTER;
listLayout.horizontalAlign = TiledRowsLayout.HORIZONTAL_ALIGN_CENTER;
_list = new List();
_list.backgroundSkin = new Quad(100, 100, 0xCCCCCC);
_list.dataProvider = collection;
_list.layout = listLayout;
_list.itemRendererFactory = tileListItemRendererFactory;
this.addChild(_list);
}
protected function tileListItemRendererFactory():IListItemRenderer
{
const renderer:DefaultListItemRenderer = new DefaultListItemRenderer();
renderer.labelField = "label2";
renderer.iconTextureField = "texture";
renderer.iconPosition = Button.ICON_POSITION_TOP;
renderer.horizontalAlign = Button.HORIZONTAL_ALIGN_CENTER;
renderer.defaultLabelProperties.textFormat = new BitmapFontTextFormat(_font, NaN, 0xff0000);
var defSkin:Image = new Image(_iconAtlas.getTexture("projector"));
renderer.defaultSkin = defSkin;
renderer.defaultSelectedSkin = defSkin;
renderer.defaultLabelProperties.textFormat = new BitmapFontTextFormat(_font, NaN, 0xff0000);
return renderer;
}
明天继续
不带主题的TileList.是OK的...
一加上MetalWorksMobile主题,label不是红色,背景是MetalWorksMobile的背景,label不是水平居中......
这个方法用来创建自定义主题....
这样写,就不对:
好习惯
所有png文件放在一个文件,用TexturePackerGUI打包
新版地址:..\CodeAndWeb\TexturePacker\bin
自定义位图字体