duilib列表项使用xml来初始化布局

来源:赵克立博客 分类: DuiLib 标签:duilib发布时间:2021-08-28 21:32:16最后更新:2021-08-28 21:32:16浏览:481
版权声明:
本文为博主原创文章,转载请声明原文链接...谢谢。o_0。
更新时间:
2021-08-28 21:32:16
温馨提示:
学无止境,技术类文章有它的时效性,请留意文章更新时间,如发现内容有误请留言指出,防止别人"踩坑",我会及时更新文章

使用duilib列表控件时列表项如果太复杂,此时使用c++代码先new出来控件,再添加到界面显的太麻烦,其实可以把列表项写成一个xml文件,使用的时候一次性加载这个xml来实例化列表项添加上去,如下一个容器

<TileLayout name="app_list" inset="5,5,0,0" childpadding="5" itemsize="90,90" vscrollbar="true" hscrollbar="false" bordercolor="#ff000000" bordersize="1"></TileLayout>

下面是列表项AppItem.xml

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Window>
    <VerticalLayout height="80">
        <HorizontalLayout height="50" bkcolor="#FFFF0000">
            <Control />
            <Button bkimage="img/unknow-32x32.png" width="32" height="32" padding="0,9,0,0" />
            <Control />
        </HorizontalLayout>
        <HorizontalLayout height="30" bkcolor="#FFFFFF00">
            <Control />
            <Label name="listmem2" text="谷歌" align="center" height="30" textcolor="#FF000000" />
            <Control />
        </HorizontalLayout>
    </VerticalLayout>
</Window>

使用方法

CTileLayoutUI* m_pTileLayout = static_cast<CTileLayoutUI*>(m_PaintManager.FindControl(_T("app_list")));

for (int i=0;i<=5;i++)
{
	CDialogBuilder builder;
	CContainerUI* pConsultFrame = static_cast<CContainerUI*>(builder.Create(_T("AppItem.xml"), (UINT)0, this, &m_pm));
	if (pConsultFrame) {
		m_pTileLayout->Add(pConsultFrame);
	}
}

效果

2108281630157530513256.png


微信号:kelicom QQ群:215861553 紧急求助须知
Win32/PHP/JS/Android/Python