列表框
<h2>列表节点</h2>
<p>节点CListItem,继承于CRelativeLayout,支持CRelativeLayout的所有属性和方法。插入列表的节点必须是CListItem或其子类。</p>
<h2>列表框</h2>
<p>列表框CListView,继承于CScrollLayout,支持CScrollLayout的所有属性和方法。</p>
<h2>属性和相关方法:</h2>
<h4>设置列表为空时的提示图片</h4>
<ul>
<li>通过XML属性控制如下:
<pre><code class="language-xml">EmptyImage="EmptyImage.png"</code></pre></li>
<li>通过C++程序代码调用方法控制如下:
<pre><code class="language-c">void SetEmptyImage(const String& strEmptyImage);</code></pre></li>
</ul>
<h4>3.4 设置列表是否允许选中Item</h4>
<ul>
<li>通过XML属性控制如下:
<pre><code class="language-xml">EmptyTips="IDS_EMPTY_TIPS"</code></pre></li>
<li>通过C++程序代码调用方法控制如下:
<pre><code class="language-c">void SetEmptyTips(const String& strEmptyTips);</code></pre></li>
</ul>
<h2>请看下面的示例</h2>
<h4>效果图</h4>
<p><img src="http://www.skinui.cn/doc/img/5.0/3/ListView.png" alt="列表控件" /></p>
<h4>简单列表框</h4>
<pre><code class="language-xml"><ListView Id="100" AlignParentLeft="40" Width="300" Height="200" AlignParentVertCenter="0">
<ListItem Width="MatchParent" Height="40" Layout="ListItem.xml" Background="ListItem.png" ChildText11="列表项1"/>
<ListItem Width="MatchParent" Height="40" Layout="ListItem.xml" Background="ListItem.png" ChildText11="列表项2"/>
<ListItem Width="MatchParent" Height="40" Layout="ListItem.xml" Background="ListItem.png" ChildText11="列表项3"/>
<ListItem Width="MatchParent" Height="40" Layout="ListItem.xml" Background="ListItem.png" ChildText11="列表项4"/>
<ListItem Width="MatchParent" Height="40" Layout="ListItem.xml" Background="ListItem.png" ChildText11="列表项5"/>
<ListItem Width="MatchParent" Height="40" Layout="ListItem.xml" Background="ListItem.png" ChildText11="列表项6"/>
<ListItem Width="MatchParent" Height="40" Layout="ListItem.xml" Background="ListItem.png" ChildText11="列表项7"/>
<ListItem Width="MatchParent" Height="40" Layout="ListItem.xml" Background="ListItem.png" ChildText11="列表项8"/>
<ListItem Width="MatchParent" Height="40" Layout="ListItem.xml" Background="ListItem.png" ChildText11="列表项9"/>
</ListView></code></pre>
<h4>复杂列表框</h4>
<pre><code class="language-xml"><ListView Id="200" AlignParentLeft="40" Width="300" Height="240" AlignParentVertCenter="0">
<ListItem Width="MatchParent" Height="60" Layout="DemoListItem.xml" Background="ListItem.png" ChildImage1="Image.png" ChildText2="姓名1" ChildText3="消息消息消息消息消息消息消息消息1"/>
<ListItem Width="MatchParent" Height="60" Layout="DemoListItem.xml" Background="ListItem.png" ChildImage1="Image.png" ChildText2="姓名2" ChildText3="消息消息消息消息消息消息消息消息2"/>
<ListItem Width="MatchParent" Height="60" Layout="DemoListItem.xml" Background="ListItem.png" ChildImage1="Image.png" ChildText2="姓名3" ChildText3="消息消息消息消息消息消息消息消息3"/>
<ListItem Width="MatchParent" Height="60" Layout="DemoListItem.xml" Background="ListItem.png" ChildImage1="Image.png" ChildText2="姓名4" ChildText3="消息消息消息消息消息消息消息消息4"/>
<ListItem Width="MatchParent" Height="60" Layout="DemoListItem.xml" Background="ListItem.png" ChildImage1="Image.png" ChildText2="姓名5" ChildText3="消息消息消息消息消息消息消息消息5"/>
<ListItem Width="MatchParent" Height="60" Layout="DemoListItem.xml" Background="ListItem.png" ChildImage1="Image.png" ChildText2="姓名6" ChildText3="消息消息消息消息消息消息消息消息6"/>
<ListItem Width="MatchParent" Height="60" Layout="DemoListItem.xml" Background="ListItem.png" ChildImage1="Image.png" ChildText2="姓名7" ChildText3="消息消息消息消息消息消息消息消息7"/>
<ListItem Width="MatchParent" Height="60" Layout="DemoListItem.xml" Background="ListItem.png" ChildImage1="Image.png" ChildText2="姓名8" ChildText3="消息消息消息消息消息消息消息消息8"/>
<ListItem Width="MatchParent" Height="60" Layout="DemoListItem.xml" Background="ListItem.png" ChildImage1="Image.png" ChildText2="姓名9" ChildText3="消息消息消息消息消息消息消息消息9"/>
</ListView></code></pre>
<h4>操作区</h4>
<pre><code class="language-xml"><FlexLayout Width="MatchParent" Height="WrapContent" Margin="40,0,20,20">
<Button Id="2001" Width="WrapContent" Height="WrapContent" Margin="0,0,20,0" Background="Button.png" Layout="Button.xml" ChildText11="插入数据"/>
<Button Id="2002" Width="WrapContent" Height="WrapContent" Margin="0,0,20,0" Background="Button.png" Layout="Button.xml" ChildText11="滚到顶部"/>
<Button Id="2003" Width="WrapContent" Height="WrapContent" Margin="0,0,20,0" Background="Button.png" Layout="Button.xml" ChildText11="滚到底部"/>
</FlexLayout></code></pre>
<h4>h文件</h4>
<pre><code class="language-cpp">#pragma once
class CDemoListViewLayout : public CScrollLayout
{
public:
enum
{
IDC_LISTVIEW = 200,
IDC_BUTTON_CLOSE = 2000,
IDC_BUTTON_INSERT = 2001,
IDC_BUTTON_SCROLL_TOP = 2002,
IDC_BUTTON_SCROLL_BOTTOM = 2003,
};
public:
CDemoListViewLayout(CView* pParent);
public:
virtual void OnBuildFinish();
protected:
void OnBtnClickedClose(UINT uNotifyCode, int nID, CView* pView);
void OnBtnClickedInsert(UINT uNotifyCode, int nID, CView* pView);
void OnBtnClickedScrollTop(UINT uNotifyCode, int nID, CView* pView);
void OnBtnClickedScrollBottom(UINT uNotifyCode, int nID, CView* pView);
SKINUI_DECLARE_MESSAGE_MAP()
private:
CListView* m_pListView;
SKINUI_DECLARE_DYNCREATE(CDemoListViewLayout, CScrollLayout)
};</code></pre>
<h4>cpp文件</h4>
<pre><code class="language-cpp">#include <stdafx.h>
#include "DemoListViewLayout.h"
SKINUI_BEGIN_MESSAGE_MAP(CDemoListViewLayout, CScrollLayout)
ON_SKINUI_COMMAND(IDC_BUTTON_CLOSE, OnBtnClickedClose)
ON_SKINUI_COMMAND(IDC_BUTTON_INSERT, OnBtnClickedInsert)
ON_SKINUI_COMMAND(IDC_BUTTON_SCROLL_TOP, OnBtnClickedScrollTop)
ON_SKINUI_COMMAND(IDC_BUTTON_SCROLL_BOTTOM, OnBtnClickedScrollBottom)
SKINUI_END_MESSAGE_MAP()
CDemoListViewLayout::CDemoListViewLayout(CView* pParent)
: CScrollLayout(pParent)
, m_pListView(NULL)
{
}
void CDemoListViewLayout::OnBuildFinish()
{
CScrollLayout::OnBuildFinish();
m_pListView = dynamic_cast<CListView*>(GetChildById(IDC_LISTVIEW));
}
void CDemoListViewLayout::OnBtnClickedClose(UINT uNotifyCode, int nID, CView* pView)
{
if(m_pListView)
{
CListItem* pListItem = dynamic_cast<CListItem*>(pView->GetParent());
if(pListItem)
{
CRedrawLocker locker(m_pListView);
m_pListView->DeleteChild(pListItem);
m_pListView->Layout();
}
}
}
void CDemoListViewLayout::OnBtnClickedInsert(UINT uNotifyCode, int nID, CView* pView)
{
static int nIndex = 10;
if(m_pListView)
{
CListItem* pListItem = new CListItem(m_pListView);
if(pListItem)
{
CRedrawLocker locker(m_pListView);
pListItem->SetBackground(_T("ListItem.png"));
pListItem->SetLayout(_T("DemoListItem.xml"));
pListItem->SetHeight(ITEM_HEIGHT_60);
pListItem->SetChildImage(1, _T("Image.png"));
pListItem->SetChildText(2, SkinUI::Format(_T("姓名%d"), nIndex++));
pListItem->SetChildText(3, SkinUI::Format(_T("消息消息消息消息消息消息消息消息%d"), nIndex));
m_pListView->Layout();
m_pListView->ScrollBottom();
}
}
}
void CDemoListViewLayout::OnBtnClickedScrollTop(UINT uNotifyCode, int nID, CView* pView)
{
if(m_pListView)
{
CListItem* pListItem = new CListItem(m_pListView);
if(pListItem)
{
CRedrawLocker locker(m_pListView);
m_pListView->ScrollTop();
}
}
}
void CDemoListViewLayout::OnBtnClickedScrollBottom(UINT uNotifyCode, int nID, CView* pView)
{
if(m_pListView)
{
CListItem* pListItem = new CListItem(m_pListView);
if(pListItem)
{
CRedrawLocker locker(m_pListView);
m_pListView->ScrollBottom();
}
}
}</code></pre>