1、概述
源码放在文章末尾
该项目实现了手机通讯录的功能,界面demo如下所示:
项目部分代码如下所示:
//联系人列表
Item{
width: parent.width
height: parent.height
anchors.centerIn: parent
Rectangle{
anchors.fill: parent
color: "#2A2D33"
}
Component {
id:sectionHeader
Item {
width: 100
height: 120
Text {
// anchors.verticalCenter: parent.verticalCenter
text: section.toUpperCase()/*.substr(0, 1)*/
font.pixelSize: 54
anchors.left: parent.left
anchors.leftMargin: 40
color: "#545a66"
anchors.bottom: parent.bottom
}
}
}
ListView{
//listview的分组不会自动排序
width:parent.width;height: parent.height-130
anchors.bottom: parent.bottom
clip: true
id:listView
// spacing:20
model: testModel
delegate: Item {
height: 120
width: parent.width
Text {
text: listView.getShowTextSpecial(name)
anchors.verticalCenter: parent.verticalCenter
color: "#858fa2"
font.pixelSize: 45
x:40
}
Rectangle{
anchors.bottom: parent.bottom
color: "#1a1c20"
width: parent.width
height: 1
}
}
ScrollIndicator.vertical: ScrollIndicator {
anchors.right: parent.right
anchors.rightMargin: 10
contentItem: Rectangle {
implicitWidth: 8
radius: implicitWidth/2
color: "#0f1115"
}
}
function getShowTextSpecial(str){
var first = str[0];
if (first === "#")
return str.substr(1);
return str;
}
section.property: "pinyin";
section.criteria: ViewSection.FirstCharacter //ViewSection.FirstCharacter//
section.delegate: sectionHeader
}